create associative array php by key value site 3astackoverflow com

Solutions on MaxInterview for create associative array php by key value site 3astackoverflow com by the best coders in the world

showing results for - "create associative array php by key value site 3astackoverflow com"
Katia
13 Nov 2018
1    function array_group(array $data, $by_column) {
2        $result = [];
3        foreach ($data as $item) {
4            $column = $item[$by_column];
5            unset($item[$by_column]);
6            if (isset($result[$column])) {
7                $result[$column][] = $item;
8            } else {
9                $result[$column] = array($item);
10            }
11        }
12        return $result;
13    }
14
15$result = array_group($assocArray,'name');