<?php
$data = [[
"continent" => "Europa",
"country" => "France",
"capital" => "Paris",
],[
"continent" => "Europa",
"country" => "Spain",
"capital" => "Madrid",
],[
"continent" => "Asia",
"country" => "Russia",
"capital" => "Moscow",
]];
$groupByContinent = function(array $list) {
return array_reduce($list, function($grouped, $item) {
$grouped[$item['continent']][] = $item;
return $grouped;
}, []);
};
$groupedByContinent = $groupByContinent($data);
var_dump($groupedByContinent);
preferences:
24.79 ms | 405 KiB | 5 Q