Answers for "create associative array php by key value site:stackoverflow.com"

PHP
0

create associative array php by key value site:stackoverflow.com

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');
Posted by: Guest on August-07-2020

Code answers related to "create associative array php by key value site:stackoverflow.com"

Browse Popular Code Answers by Language