Count similar elements in array php

Hi everybody,suppose your array is something like the below example:

Array ([0] => Array( [date] => 2014-04-14 ) [1] => Array ([date] => 2014-04-10 )
[2] => Array([date] => 2014-04-10) [3] => Array([date] => 2014-04-09 ) )

So you can count all of the matching values in an array with below code:

echo array_count_values(array_column($arr, ‘date’));

It will result following output:

Array ( [2014-04-14] => 1 [2014-04-10] => 2 [2014-04-09] => 1 )

Leave a Reply

Your email address will not be published. Required fields are marked *

*