📅  最后修改于: 2022-03-11 14:54:36.006000             🧑  作者: Mango
/* Collapse on common columns which is also the new key e.g.
([0] => [[id] => 1234, [firstName] => "foo", [1] => [[id] => 1234, [lastName] => "bar")
will become ([1234] => [[firstName] => "foo", [lastName]="bar"]
Credit to https://stackoverflow.com/users/762073/xdazz
*/
$result = array();
foreach ($data as $element) {
$result[$element['id']][] = $element;// [] appends to the array if it already exists
}