I have a PHP array that looks like this...
Array
(
[item1] => Array
(
[0] => 1
[1] => 1
[2] => 1
)
[item2] => Array
(
[0] => 1
[1] => 1
[2] => 1
[3] => 1
[4] => 1
[5] => 2
)
)
I am trying to count the values and output a new array that looks like this...
Array
(
[item1] => Array
(
[1] => 3
)
[item2] => Array
(
[1] => 5
[2] => 1
)
)
I have tried to get the count by doing this...
print_r(array_count_values($myarray));
But this is not working for me, is there a way to count the values and creaye the new array all in one statement?
array_count_valuesworks on one array. You have an array of arrays. You need some sort of loop here. Hint:array_map…