3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $array = [ [ 'name' => 'Foo', 'children' => [ 'B', 'A' ] ], [ 'name' => 'Bar', 'children' => [ 'Z', 'X', 'Y' ] ] ]; usort($array, function(&$x, &$y) { sort($x['children']); sort($y['children']); var_dump($x['children'], $y['children']); return strcasecmp($x['name'], $y['name']); }); var_dump($array);
based on qX95B
Output for 7.0.0 - 7.2.0
array(2) { [0]=> string(1) "A" [1]=> string(1) "B" } array(3) { [0]=> string(1) "X" [1]=> string(1) "Y" [2]=> string(1) "Z" } array(2) { [0]=> array(2) { ["name"]=> string(3) "Bar" ["children"]=> array(3) { [0]=> string(1) "Z" [1]=> string(1) "X" [2]=> string(1) "Y" } } [1]=> array(2) { ["name"]=> string(3) "Foo" ["children"]=> array(2) { [0]=> string(1) "B" [1]=> string(1) "A" } } }
Output for 5.4.11 - 5.6.28
array(3) { [0]=> string(1) "X" [1]=> string(1) "Y" [2]=> string(1) "Z" } array(2) { [0]=> string(1) "A" [1]=> string(1) "B" } array(2) { [0]=> array(2) { ["name"]=> string(3) "Bar" ["children"]=> array(3) { [0]=> string(1) "X" [1]=> string(1) "Y" [2]=> string(1) "Z" } } [1]=> array(2) { ["name"]=> string(3) "Foo" ["children"]=> array(2) { [0]=> string(1) "A" [1]=> string(1) "B" } } }
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/R3KFA on line 3
Process exited with code 255.