Filip  Busic Filip Busic - 5 months ago 25
PHP Question

Counting Values in Multidimensional Array PHP

I know this question has already been answered a few times, however, none of the answers apply to my scenario.

Current Array:

Array
(
[12] => Array
(
[0] => 1AM
[1] => 2AM
[2] => 3AM
[3] => 4AM
)

[13] => Array
(
[0] => 1AM
[1] => 2AM
[2] => 6AM
[3] => 4AM
)

[14] => Array
(
[0] => 1AM
[1] => 2AM
[2] => 7AM
[3] => 4AM
)

)


Desired Output:

3 People Signed Up at 1AM,

3 People signed up at 2AM,

1 Signed up at 3AM

1 Signed up at 6AM

1 Signed up at 7AM

3 Signed up at 4AM


Current code:

foreach($array as $k => $v) {
$result[$k] = array_count_values($v);
arsort($result[$k]);
}
print_r($result);


In other words, just counting the times and storing them in a separate array or variable.

Answer

You can simply use array_count_values along with call_user_func_array like as

array_count_values(call_user_func_array('array_merge', $array));