Thursday, January 30, 2014

To count all the values of an array. 'array_count_values()'


If you have an array like this
Array
(
    [0] => Ford
    [1] => Ford
    [2] => BMW
    [3] => Ford
    [4] => BMW
    [5] => Ford
    [6] => Audi
    [7] => Benz
)
and you need to count the same array values then we can use

array_count_values(array)
This will give you the out put as

Array
(
    [Ford] => 4
    [BMW] => 2
    [Audi] => 1
    [Benz] =>1
)