3v4l.org

run code in 200+ PHP versions simultaneously
<?php function partition(&$arr, $left, $right) { $pivot = $arr[($left + $right)/2]; while ($left <= $right) { while ($arr[$left] < $pivot) $left++; while ($arr[$right] > $pivot) $right--; if ($left <= $right) { $tmp = $arr[$left]; $arr[$left] = $arr[$right]; $arr[$right] = $tmp; $left++; $right--; } } return $left; } function quickSort($arr, $left = 0, $right = null) { if(!$right) $right = (count($arr)-1); $index = partition($arr, $left, $right); if ($left < $index - 1) { $arr = quickSort($arr, $left, $index - 1); } if ($index < $right) { $arr = quickSort($arr, $index, $right); } return $arr; } $sortMe = [8,11,10,13,4,12,56,9]; print_r(quickSort($sortMe));
Output for 5.4.0 - 7.4.1
Array ( [0] => 4 [1] => 8 [2] => 9 [3] => 10 [4] => 11 [5] => 12 [6] => 13 [7] => 56 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/Vm4rd on line 40
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/Vm4rd on line 40
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/Vm4rd on line 40
Process exited with code 255.