📜  php 折叠关联数组中的常用列 - PHP 代码示例

📅  最后修改于: 2022-03-11 14:54:36.006000             🧑  作者: Mango

代码示例1
/* 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
}