function sortArr($result, $data){
foreach ($data as $k => $v) {
if (! array_key_exists($k, $result)) {
$result[$k] = [$v];
} else {
array_push($result[$k], $v);
}
}
return $result;
}
$test = sortArr([], [ 'a' => 1, 'b' => 2, 'a' => 3 ]);
print_r($test);
Array
(
[a] => Array
(
[0] => 3
)
[b] => Array
(
[0] => 2
)
)
Array
(
[a] => Array
(
[0] => 1
[1] => 3
)
[b] => Array
(
[0] => 2
)
)