php - Count times same value is in array -
this question has answer here:
i have question,
if have following array:
array ( [0] => apple [1] => apple [3] => banana [4] => apple )
is there way count how many times same value occurs in array?
so in example how many times apple occurs in array.
thanks in advance!!
you can use php array_count_values() function.
array_count_values($your_array); <?php $array = array("apple", "apple", "banana", "apple"); print_r(array_count_values($array)); ?> //output array ( [apple] => 3 [banana] => 1 )
Comments
Post a Comment