Group rows in an associative array of associative arrays by column value and preserve the original first level keys March 2, 2023 by Tarik $arr = array(); foreach ($old_arr as $key => $item) { $arr[$item['id']][$key] = $item; } ksort($arr, SORT_NUMERIC);