3v4l.org

run code in 300+ PHP versions simultaneously
<?php $snippet = '<?foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]);'; echo 'Byte length: ' , strlen($snippet) , "\n"; $_GET[A] = [3, 2, 2, 3]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[3, 0, 3], [2, 1, 2]] echo "\n---\n"; unset($b); $_GET[A] = [17]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[17, 0]] echo "\n---\n"; unset($b); $_GET[A] = [1, 1]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[1, 0, 1]] echo "\n---\n"; unset($b); $_GET[A] = [1, 1, 2]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[1, 0, 1], [2, 2]] echo "\n---\n"; unset($b); $_GET[A] = [1, 2, 3, 4]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[1, 0], [2, 1], [3, 2], [4, 3]] echo "\n---\n"; unset($b); $_GET[A] = [1, 1, 1, 1]; foreach($_GET[A]as$k=>$v){$b[$v][0]=$v;$b[$v][]=$k;}print_r([...$b]); // [[1, 0, 1, 2, 3]]
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.4, 8.3.6
Byte length: 71 Fatal error: Uncaught Error: Undefined constant "A" in /in/UHQWO:5 Stack trace: #0 {main} thrown in /in/UHQWO on line 5
Process exited with code 255.
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 Byte length: 71 Fatal error: Uncaught Error: Undefined constant "A" in /in/UHQWO:5 Stack trace: #0 {main} thrown in /in/UHQWO on line 5
Process exited with code 255.
Output for 7.4.4 - 7.4.33
Byte length: 71 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 5 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 6 Array ( [0] => Array ( [0] => 3 [1] => 0 [2] => 3 ) [1] => Array ( [0] => 2 [1] => 1 [2] => 2 ) ) --- Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 10 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 11 Array ( [0] => Array ( [0] => 17 [1] => 0 ) ) --- Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 15 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 16 Array ( [0] => Array ( [0] => 1 [1] => 0 [2] => 1 ) ) --- Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 20 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 21 Array ( [0] => Array ( [0] => 1 [1] => 0 [2] => 1 ) [1] => Array ( [0] => 2 [1] => 2 ) ) --- Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 25 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 26 Array ( [0] => Array ( [0] => 1 [1] => 0 ) [1] => Array ( [0] => 2 [1] => 1 ) [2] => Array ( [0] => 3 [1] => 2 ) [3] => Array ( [0] => 4 [1] => 3 ) ) --- Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 30 Warning: Use of undefined constant A - assumed 'A' (this will throw an Error in a future version of PHP) in /in/UHQWO on line 31 Array ( [0] => Array ( [0] => 1 [1] => 0 [2] => 1 [3] => 2 [4] => 3 ) )
Output for 7.1.25 - 7.1.32, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '...' (T_ELLIPSIS), expecting ']' in /in/UHQWO on line 6
Process exited with code 255.

preferences:
183.93 ms | 402 KiB | 174 Q