3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = array(); echo PHP_EOL . ' on empty array: ' . PHP_EOL; var_dump(key($array)); $array[] = 'f'; echo PHP_EOL . ' size one array: ' . PHP_EOL; var_dump(key($array)); $array[] = 'f'; echo PHP_EOL . ' size two array: ' . PHP_EOL; var_dump(key($array)); echo PHP_EOL . ' within loop: ' . PHP_EOL; foreach ($array as $key => $value) { var_dump(key($array)); if ($key == 0) { echo PHP_EOL . ' unsetting first element.... ' . PHP_EOL; unset($array[$key]); } if ($key == 1) { echo PHP_EOL . ' unsetting second element.... ' . PHP_EOL; unset($array[$key]); } } echo PHP_EOL . ' after loop: ' . PHP_EOL; var_dump(key($array)); reset($array); echo PHP_EOL . ' after reset: ' . PHP_EOL; var_dump(key($array)); end($array); echo PHP_EOL . ' after end: ' . PHP_EOL; var_dump(key($array)); echo PHP_EOL . ' trying to trigger "Undefined index: " error: with NULL key' . PHP_EOL; $array[null]; echo PHP_EOL . ' trying to trigger "Undefined index: " error: with empty string key' . PHP_EOL; $array[''];
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.6
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key Warning: Undefined array key "" in /in/btrIb on line 40 trying to trigger "Undefined index: " error: with empty string key Warning: Undefined array key "" in /in/btrIb on line 43
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.12 - 7.3.31, 7.4.0 - 7.4.25, 7.4.27 - 7.4.33
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/btrIb on line 40 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/btrIb on line 43
Output for 7.3.32 - 7.3.33, 7.4.26
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key trying to trigger "Undefined index: " error: with empty string key
Output for 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.24 - 5.5.35, 5.6.7 - 5.6.21
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(1) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/btrIb on line 40 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/btrIb on line 43
Output for 4.4.1, 5.2.4 - 5.2.17
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(1) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/btrIb on line 40 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/btrIb on line 43
Output for 4.3.10 - 4.3.11, 4.4.0, 4.4.2 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.3
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) unsetting first element.... int(1) unsetting second element.... after loop: NULL after reset: NULL after end: NULL trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/btrIb on line 40 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/btrIb on line 43
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 3 PHP_EOL on empty array: PHP_EOLNULL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 7 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 7 PHP_EOL size one array: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 11 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 11 PHP_EOL size two array: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 14 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 14 PHP_EOL within loop: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 18 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 18 PHP_EOL unsetting first element.... PHP_EOLint(1) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 23 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 23 PHP_EOL unsetting second element.... PHP_EOL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 28 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 28 PHP_EOL after loop: PHP_EOLNULL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 32 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 32 PHP_EOL after reset: PHP_EOLNULL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 36 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 36 PHP_EOL after end: PHP_EOLNULL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 39 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 39 PHP_EOL trying to trigger "Undefined index: " error: with NULL keyPHP_EOL Notice: Undefined index: in /in/btrIb on line 40 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 42 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/btrIb on line 42 PHP_EOL trying to trigger "Undefined index: " error: with empty string keyPHP_EOL Notice: Undefined index: in /in/btrIb on line 43

preferences:
220.11 ms | 410 KiB | 314 Q