3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ [ 'id' => 2, 'position' => 2, ], [ 'id' => 1, 'position' => 1, ], [ 'id' => 1, 'position' => 0, ], [ 'id' => 2, 'position' => 1, ], [ 'id' => 2, 'position' => 0, ], [ 'id' => 1, 'position' => 2, ], ]; usort( $data, function ($a, $b) { if ($a['position'] == $b['position']) { return 0; } return ($a['position'] < $b['position']) ? -1 : 1; } ); // usort( // $data, // function ($a, $b) { // if ($a['id'] == $b['id']) { // return 0; // } // return ($a['id'] < $b['id']) ? -1 : 1; // } // ); var_dump($data);
Output for git.master, git.master_jit, rfc.property-hooks
array(6) { [0]=> array(2) { ["id"]=> int(1) ["position"]=> int(0) } [1]=> array(2) { ["id"]=> int(2) ["position"]=> int(0) } [2]=> array(2) { ["id"]=> int(1) ["position"]=> int(1) } [3]=> array(2) { ["id"]=> int(2) ["position"]=> int(1) } [4]=> array(2) { ["id"]=> int(2) ["position"]=> int(2) } [5]=> array(2) { ["id"]=> int(1) ["position"]=> int(2) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
44.64 ms | 402 KiB | 8 Q