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.31, 8.2.0 - 8.2.27, 8.3.0 - 8.3.15, 8.4.1 - 8.4.2
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:
83.51 ms | 407 KiB | 5 Q