Group subarrays by one column, make comma-separated values from other column within groups
问题 I have a array that looks like this: $array = [ ["444", "0081"], ["449", "0081"], ["451", "0081"], ["455", "2100"], ["469", "2100"] ]; I need to group as a new array that looks like: array ( 0 => array ( 0 => '444,449,451', 1 => '0081', ), 1 => array ( 0 => '455,469', 1 => '2100', ), ) I'd tried many scripts, but with no success. function _group_by($array, $key) { $return = array(); foreach($array as $val) { $return[$val[$key]][] = $val; } return $return; } $newArray = _group_by($array, 1); /