3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ ['id' => 1, 'position' => 7], ['id' => 3, 'position' => 2], ['id' => 2, 'position' => 1], ['id' => 4, 'position' => 4], ]; $n = sizeof($arr); for($i = 0; $i < $n; $i++) { for ($j = 0; $j < $n - $i - 1; $j++) { if ($arr[$j]['position'] > $arr[$j+1]['position']) { $t = $arr[$j]; $arr[$j] = $arr[$j+1]; $arr[$j+1] = $t; } } } print '<pre>'; print_r($arr);
Output for 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
<pre>Array ( [0] => Array ( [id] => 2 [position] => 1 ) [1] => Array ( [id] => 3 [position] => 2 ) [2] => Array ( [id] => 4 [position] => 4 ) [3] => Array ( [id] => 1 [position] => 7 ) )

preferences:
131.18 ms | 404 KiB | 227 Q