3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(0); function f($s){ for($i=0,$n=count($s)-1;$j++<=$n;) if($k=$s[$j]){ $l=$k>0?n:i; ($x=$s[$$l])|($s[$$l]=$k)|($s[$j]=$x); $k>0?$n--|$j--:$i++; } echo print_r($s); } echo "-------------\n"; f( [5, 3, 0, -6, 2, 0, 5] ); echo "\n"; echo "-------------\n";
Output for 8.0.0 - 8.0.10, 8.1rc1 - rc2
-------------
Process exited with code 255.
Output for 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.8 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.5 - 7.2.33, 7.3.16 - 7.3.30, 7.4.0 - 7.4.23
------------- Array ( [0] => -6 [1] => 0 [2] => 0 [3] => 2 [4] => 5 [5] => 5 [6] => 3 ) 1 -------------
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/ivRX5 on line 16
Process exited with code 255.
Output for 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ')' in /in/ivRX5 on line 16
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/ivRX5 on line 16
Process exited with code 255.

preferences:
71.39 ms | 464 KiB | 5 Q