I have the following array:
(
[25] => 1
[26] => 3
[10] => 2
[24] => 1
)
It was created using the array_count_values() function in PHP.
Actual original array was something like this, before array_count_values...
Array
(
[0] => 26
[1] =>
[2] => 18
[3] => 28
[4] => 22
[5] => 21
[6] => 26
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
[15] =>
[16] =>
[17] =>
[18] =>
[19] =>
[20] =>
)
These are ages, so how can I group these into age groups?
Lets say I want the following age groups: <= 18 19-26 27-32 > 32
It is supposed to look:
(
[<= 18] => 1
[19-26] => 4
[27-32] => 2
[ > 32] => 1
)
Is there a ready function for this?
My solution:
1 tedious way would be to create variables of age groups. Than foreach and increase variable ++ for specific age group if key matches range ($min <= $value) && ($value <= $max)...
array_count_values()output, you have 2 people in the < 18 category, 5 people in the 19-26 category, and nobody in the remaining categories.