K.I.S.S
But how about some error and misuse control? I am wishing it were .NET HAHA.
<?php
function array_group_by($arr, $key_selector) {
$result = array();
foreach($arr as $i){
$key = $key_selector($i);
if(!array_key_exists($key, $result)) {
$result[$key] = array();
}
$result[$key][] = $i;
}
return $result;
}
$data = array(
array(1, "Andy", "PHP"),
array(1, "Andy", "C#"),
array(2, "Josh", "C#"),
array(2, "Josh", "ASP"),
array(1, "Andy", "SQL"),
array(3, "Steve", "SQL"),
);
$grouped = array_group_by($data, function($i){ return $i[0]; });
var_dump($grouped);
?>