Transforming an array into multilevel array (PHP)

In PHP there is function array_combine(). This function may not work as expected in the case if a key is met more than once. For this reason, I created the following function: function array_combine_array($keyname, $array) { $ret = array(); foreach($array as $value) { $key = $value[$keyname]; if(!isset($ret[$key])) $ret[$key] = array(); array_push($ret[$key], $value); } return $ret; } This function behaves like array_combine() but in its result … Continue reading Transforming an array into multilevel array (PHP)