Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
$students = [
[
"country" => "japan",
"school" => "kyoto university",
"name" => "Naruto Uzumaki"
],
[
"country" => "usa",
"school" => "harvard university",
"name" => "Naruto Uzumaki"
],
[
"country" => "japan",
"school" => "tokyo university",
"name" => "sasuke Uchiha"
],
[
"country" => "japan",
"school" => "tokyo university",
"name" => "kakashi hatake"
],
];
$result = [];
foreach ($students as $student) {
extract($student);
$result[$country][$school][] = $student;
}
var_export($result);