Share on Google+Share on Google+

PHP array count

This section demonstrates how to count the number of elements in array using array_count_values() function

  • The PHP array_count_values() function is used to count the elements in the array.
  • It returns the number of counting with values in associative array form.
  • In returned array, key is the array's values and values are the number of occurrences.

Example of PHP Array Count

($arr as $key=>$val)
"<br>key $key value $val";


    Array ( [aaa] => 2 [bbb] => 2 [ccc] => 1 [ddd] => 1 [ggg] => 1 )
    key aaa value 2
    key bbb value 2
    key ccc value 1
    key ddd value 1
    key ggg value 1



Posted on: October 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.


Advertisement null