3v4l.org

run code in 200+ 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]]
based on cTPLe
Output for 7.4.0alpha1 - 7.4.0beta4
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.3.9
Parse error: syntax error, unexpected '...' (T_ELLIPSIS), expecting ']' in /in/UHQWO on line 6
Process exited with code 255.