<?php
$array = [
[
'name' => 'Foo',
'children' => [
[
'name' => 'B',
'children' => []
],
[
'name' => 'A',
'children' => []
]
]
],
[
'name' => 'Bar',
'children' => [
[
'name' => 'Z',
'children' => []
],
[
'name' => 'X',
'children' => []
],
[
'name' => 'Y',
'children' => []
]
]
]
];
usort($array, $f = function(&$x, &$y) use (&$f, $array){
usort($x['children'], $f);
usort($y['children'], $f);
var_dump($x['children'], $array);
return strcasecmp($x['name'], $y['name']);
});
- Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
- Warning: {closure}(): Argument #1 ($x) must be passed by reference, value given in /in/gPd1o on line 36
Warning: {closure}(): Argument #2 ($y) must be passed by reference, value given in /in/gPd1o on line 36
Warning: {closure}(): Argument #1 ($x) must be passed by reference, value given in /in/gPd1o on line 37
Warning: {closure}(): Argument #2 ($y) must be passed by reference, value given in /in/gPd1o on line 37
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
Warning: {closure}(): Argument #1 ($x) must be passed by reference, value given in /in/gPd1o on line 38
Warning: {closure}(): Argument #2 ($y) must be passed by reference, value given in /in/gPd1o on line 38
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
Warning: {closure}(): Argument #1 ($x) must be passed by reference, value given in /in/gPd1o on line 38
Warning: {closure}(): Argument #2 ($y) must be passed by reference, value given in /in/gPd1o on line 38
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
Warning: {closure}(): Argument #1 ($x) must be passed by reference, value given in /in/gPd1o on line 38
Warning: {closure}(): Argument #2 ($y) must be passed by reference, value given in /in/gPd1o on line 38
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
- Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.33
- array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
- Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.21
- array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(0) {
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
}
array(2) {
[0]=>
array(2) {
["name"]=>
string(3) "Foo"
["children"]=>
array(2) {
[0]=>
array(2) {
["name"]=>
string(1) "B"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "A"
["children"]=>
array(0) {
}
}
}
}
[1]=>
array(2) {
["name"]=>
string(3) "Bar"
["children"]=>
array(3) {
[0]=>
array(2) {
["name"]=>
string(1) "Z"
["children"]=>
array(0) {
}
}
[1]=>
array(2) {
["name"]=>
string(1) "X"
["children"]=>
array(0) {
}
}
[2]=>
array(2) {
["name"]=>
string(1) "Y"
["children"]=>
array(0) {
}
}
}
}
}
preferences:
175.15 ms | 414 KiB | 181 Q