3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?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 $item) { var_dump(key($array)); } 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 hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) int(0) after loop: int(0) after reset: int(0) after end: int(1) trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/lsXp5 on line 31 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/lsXp5 on line 34
Output for 5.3.0 - 5.6.28
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(1) int(1) after loop: int(1) after reset: int(0) after end: int(1) trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/lsXp5 on line 31 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/lsXp5 on line 34
Output for 5.2.4 - 5.2.17
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(1) int(1) after loop: int(1) after reset: int(0) after end: int(1) trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/lsXp5 on line 31 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/lsXp5 on line 34
Output for 4.3.10 - 4.4.0, 4.4.2 - 4.4.9, 5.0.2 - 5.2.3
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(0) int(0) after loop: int(0) after reset: int(0) after end: int(1) trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/lsXp5 on line 31 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/lsXp5 on line 34
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/lsXp5 on line 3 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 3 PHP_EOL on empty array: PHP_EOLNULL Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 7 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 7 PHP_EOL size one array: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 11 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 11 PHP_EOL size two array: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 14 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 14 PHP_EOL within loop: PHP_EOLint(0) int(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 19 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 19 PHP_EOL after loop: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 23 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 23 PHP_EOL after reset: PHP_EOLint(0) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 27 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 27 PHP_EOL after end: PHP_EOLint(1) Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 30 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 30 PHP_EOL trying to trigger "Undefined index: " error: with NULL keyPHP_EOL Notice: Undefined index: in /in/lsXp5 on line 31 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 33 Notice: Use of undefined constant PHP_EOL - assumed 'PHP_EOL' in /in/lsXp5 on line 33 PHP_EOL trying to trigger "Undefined index: " error: with empty string keyPHP_EOL Notice: Undefined index: in /in/lsXp5 on line 34
Output for 4.4.1
on empty array: NULL size one array: int(0) size two array: int(0) within loop: int(1) NULL after loop: NULL after reset: int(0) after end: int(1) trying to trigger "Undefined index: " error: with NULL key Notice: Undefined index: in /in/lsXp5 on line 31 trying to trigger "Undefined index: " error: with empty string key Notice: Undefined index: in /in/lsXp5 on line 34