Posted on June 15, 2021 by winnieHow to group an array of associative arrays by key in PHP $result = array(); foreach ($data as $element) { $result[$element['id']][] = $element; }