3v4l.org

run code in 300+ PHP versions simultaneously
<?php function array_swap(&$input, $num) { $tmp = $input[0]; $input[0] = $input[$num]; $input[$num] = $tmp; } $input = [4, 5, 8, 9, 1, 7, 2]; function xsort($oldArray) { $newArray = array(); foreach($oldArray as $arr){ $newArray[] = $arr; } return $newArray; } var_dump(xsort($input));

preferences:
64.06 ms | 402 KiB | 5 Q