3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a = 'time'; $b = 'more'; $array = array( $a, $b ); var_dump($array); var_dump($array[1]); echo PHP_EOL; $array = compact( 'a', 'b' ); var_dump($array); var_dump($array[1]);
Output for 8.0.1 - 8.0.30, 8.1.0 - 8.1.29, 8.2.0 - 8.2.20, 8.3.0 - 8.3.8
array(2) { [0]=> string(4) "time" [1]=> string(4) "more" } string(4) "more" array(2) { ["a"]=> string(4) "time" ["b"]=> string(4) "more" } Warning: Undefined array key 1 in /in/gUWOB on line 14 NULL
Output for 7.4.0 - 7.4.33
array(2) { [0]=> string(4) "time" [1]=> string(4) "more" } string(4) "more" array(2) { ["a"]=> string(4) "time" ["b"]=> string(4) "more" } Notice: Undefined offset: 1 in /in/gUWOB on line 14 NULL

preferences:
140.31 ms | 402 KiB | 126 Q