3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $data = [ [ 'id' => 2, 'position' => 3, ], [ 'id' => 1, 'position' => 2, ], [ 'id' => 1, 'position' => 1, ], [ 'id' => 2, 'position' => 2, ], [ 'id' => 2, 'position' => 1, ], [ 'id' => 1, 'position' => 3, ], ]; usort( $data, function ($a, $b) { if ($a['id'] == $b['id'] && $a['position'] == $b['position']) { return 0; } return ($a['id'] < $b['id'] && $a['position'] < $b['position']) ? -1 : 1; } ); var_dump($data);
Output for 7.0.0 - 7.2.0
array(6) { [0]=> array(2) { ["id"]=> int(1) ["position"]=> int(3) } [1]=> array(2) { ["id"]=> int(2) ["position"]=> int(1) } [2]=> array(2) { ["id"]=> int(1) ["position"]=> int(1) } [3]=> array(2) { ["id"]=> int(2) ["position"]=> int(2) } [4]=> array(2) { ["id"]=> int(1) ["position"]=> int(2) } [5]=> array(2) { ["id"]=> int(2) ["position"]=> int(3) } }
Output for 5.4.10 - 5.6.28
array(6) { [0]=> array(2) { ["id"]=> int(1) ["position"]=> int(2) } [1]=> array(2) { ["id"]=> int(1) ["position"]=> int(1) } [2]=> array(2) { ["id"]=> int(2) ["position"]=> int(1) } [3]=> array(2) { ["id"]=> int(2) ["position"]=> int(3) } [4]=> array(2) { ["id"]=> int(2) ["position"]=> int(2) } [5]=> array(2) { ["id"]=> int(1) ["position"]=> int(3) } }
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/7kke9 on line 3
Process exited with code 255.