php create multidimensional array with column name code example
Example: php collapse common columns in associative array
/* 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
}