PHP array_count_values() function
In this chapter you will learn:
- Definition for PHP array_count_values() function
- Syntax for PHP array_count_values() function
- Parameter for PHP array_count_values() function
- Return value from PHP array_count_values() function
- Example - Count all the values of an array
- Example - Count an associative array
Definition
The array_count_values() function counts the values of an array.
Syntax
PHP array_count_values() function has the following syntax.
array_count_values(array)
Parameter
- array - Required. Array to count
Return
It returns an associative array, where the keys are the original array's values, and the values are the number of occurrences.
Example 1
Count all the values of an array
<?php
$a=array("A","Cat","Dog","A","Dog");
print_r(array_count_values($a));
?>
The code above generates the following result.
Example 2
Count an associative array
<?php
$age=array("PHP"=>"5","Python"=>"7","Java"=>"3");
print_r(array_count_values($age));
?>
The code above generates the following result.
Next chapter...
What you will learn in the next chapter:
- Syntax for PHP array_diff() function
- Description for PHP array_diff() function
- Parameter for PHP array_diff() function
- Example - Find the difference between two arrays
- Example - Different two associative arrays
Home » PHP Tutorial » PHP Array Functions