📜  通过键值创建关联数组 php site:stackoverflow.com - PHP 代码示例

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

代码示例1
function array_group(array $data, $by_column) {
        $result = [];
        foreach ($data as $item) {
            $column = $item[$by_column];
            unset($item[$by_column]);
            if (isset($result[$column])) {
                $result[$column][] = $item;
            } else {
                $result[$column] = array($item);
            }
        }
        return $result;
    }

$result = array_group($assocArray,'name');