I currently have the following array:
Array(
[0] => Array
(
[user] => Name 1
[group] => 1
This can be done with a simple iteration:
$counts = array();
foreach ($array as $key=>$subarr) {
// Add to the current group count if it exists
if (isset($counts[$subarr['group']]) {
$counts[$subarr['group']]++;
}
// or initialize to 1 if it doesn't exist
else $counts[$subarr['group']] = 1;
// Or the ternary one-liner version
// instead of the preceding if/else block
$counts[$subarr['group']] = isset($counts[$subarr['group']]) ? $counts[$subarr['group']]++ : 1;
}
In PHP 5.5, which has added the array_column() function to aggregate an inner key from a 2D array, this can be simplified to:
$counts = array_count_values(array_flip(array_column($array, 'group')));