3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $arr = [ 1,3,1,8,9,7,2,0,-1,6,4 ]; print_r($arr); uasort($arr, function($a, $b){ return abs(3-$a) - abs(3-$b); }); print_r($arr);
based on u0roh
Output for 7.0.0 - 7.2.0
Array ( [0] => 1 [1] => 3 [2] => 1 [3] => 8 [4] => 9 [5] => 7 [6] => 2 [7] => 0 [8] => -1 [9] => 6 [10] => 4 ) Array ( [1] => 3 [6] => 2 [10] => 4 [0] => 1 [2] => 1 [7] => 0 [9] => 6 [5] => 7 [8] => -1 [3] => 8 [4] => 9 )
Output for 5.4.0 - 5.6.28
Array ( [0] => 1 [1] => 3 [2] => 1 [3] => 8 [4] => 9 [5] => 7 [6] => 2 [7] => 0 [8] => -1 [9] => 6 [10] => 4 ) Array ( [1] => 3 [6] => 2 [10] => 4 [2] => 1 [0] => 1 [7] => 0 [9] => 6 [8] => -1 [5] => 7 [3] => 8 [4] => 9 )
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/mtpPM on line 5
Process exited with code 255.