Recommend this page to a friend! |
![]() |
Info | Documentation | ![]() |
![]() |
![]() |
Reputation | Support forum | Blog | Links |
Ratings | Unique User Downloads | Download Rankings | ||||
Not yet rated by the users | Total: 177 | All time: 8,750 This week: 206![]() |
Version | License | PHP version | Categories | |||
countval 2.0.1 | The PHP License | 5 | PHP 5, Data types |
Extends PHP array_count_values native function to count any PHP type value in iterable variables
Requires: PHP 5.3+
Typically you would use it:
Require the library by issuing this command:
composer require manuwhat/avc
Add require 'vendor/autoload.php';
to the top of your script.
require 'AVC.php';//require helpers file
var_dump(count_values(array_merge(range(0, 5), array(array()), array(array()), array(array(6)))));
/* output
array(8) {
[0]=>
array(2) {
[0]=>
int(0)
[1]=>
int(1)
}
[1]=>
array(2) {
[0]=>
int(1)
[1]=>
int(1)
}
[2]=>
array(2) {
[0]=>
int(2)
[1]=>
int(1)
}
[3]=>
array(2) {
[0]=>
int(3)
[1]=>
int(1)
}
[4]=>
array(2) {
[0]=>
int(4)
[1]=>
int(1)
}
[5]=>
array(2) {
[0]=>
int(5)
[1]=>
int(1)
}
[6]=>
array(2) {
[0]=>
array(0) {
}
[1]=>
int(2)
}
[7]=>
array(2) {
[0]=>
array(1) {
[0]=>
int(6)
}
[1]=>
int(1)
}
}
*/
AS you may see the result is a multi-dimensional array and this is great but not very convenient. So the package provide an iterator to easily handle the result.One can use it this way:
require 'AVC.php';//require helpers file
$x=count_values(array_merge(range(0, 5), array(array()), array(array()), array(array(6))),true);
foreach ($x as $value=>$count){
if(is_array($value)||is_object($value)){
var_dump($value);
}elseif(is_resource($value)){
var_dump(stream_get_meta_data ($value));
}else{
echo "$value=>$count<br>";
}
}
When the handled variable doesn't contain type other than integer or string the function return exactly the same output as the native array_count_values function except if an iterator have been required.
Note that when the handled variable contain types other than integer and string and an iterator has been required as result, you can access the count using array access syntax .For example:
require 'AVC.php';//require helpers file
$x=count_values(array_merge(range(0, 5), array(array()), array(array()), array(array(6))),true);
echo $x[array()];
/*
output:
2
*/
3 helpers are provided in the AVC.php file
count_values,value_count,count_diff_values
To run unit tests
phpunit ./tests
![]() |
File | Role | Description | ||
---|---|---|---|---|
![]() |
||||
![]() |
||||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Aux. | Auxiliary script | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Lic. | License text | ||
![]() ![]() |
Data | Auxiliary data | ||
![]() ![]() |
Doc. | Documentation | ||
![]() ![]() |
Doc. | readme |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
![]() |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
90% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.