3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $books["978-0743261690"] = "Gilgamesh"; $books["978-0060931957"] = "The Odyssey"; $books["978-0192840509"] = "Aesop's Fables"; $books["978-0520227040"] = "Mahabharta"; $books["978-0393320978"] = "Beowulf"; ?><html> <head> <title>Five Great Books</title> </head> <body> <h1>Five Great Books</h1> <ul> <?php foreach($books as $book) { ?> <li><?php echo key($book); ?></li> <?php } ?> </ul> </body> </html>
based on knKrf
Output for 5.3.0 - 5.6.28, 7.0.0 - 7.1.0
<html> <head> <title>Five Great Books</title> </head> <body> <h1>Five Great Books</h1> <ul> <li> Warning: key() expects parameter 1 to be array, string given in /in/vuUhf on line 17 </li> <li> Warning: key() expects parameter 1 to be array, string given in /in/vuUhf on line 17 </li> <li> Warning: key() expects parameter 1 to be array, string given in /in/vuUhf on line 17 </li> <li> Warning: key() expects parameter 1 to be array, string given in /in/vuUhf on line 17 </li> <li> Warning: key() expects parameter 1 to be array, string given in /in/vuUhf on line 17 </li> </ul> </body> </html>
Output for hhvm-3.10.0 - 3.12.0
<html> <head> <title>Five Great Books</title> </head> <body> <h1>Five Great Books</h1> <ul> <li> Warning: Invalid operand type was used: expecting an array in /in/vuUhf on line 17 </li> <li> Warning: Invalid operand type was used: expecting an array in /in/vuUhf on line 17 </li> <li> Warning: Invalid operand type was used: expecting an array in /in/vuUhf on line 17 </li> <li> Warning: Invalid operand type was used: expecting an array in /in/vuUhf on line 17 </li> <li> Warning: Invalid operand type was used: expecting an array in /in/vuUhf on line 17 </li> </ul> </body> </html>
Output for 4.3.2 - 5.2.17
<html> <head> <title>Five Great Books</title> </head> <body> <h1>Five Great Books</h1> <ul> <li> Warning: key(): Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key(): Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key(): Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key(): Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key(): Passed variable is not an array or object in /in/vuUhf on line 17 </li> </ul> </body> </html>
Output for 4.3.0 - 4.3.1
<html> <head> <title>Five Great Books</title> </head> <body> <h1>Five Great Books</h1> <ul> <li> Warning: key() [http://www.php.net/function.key]: Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key() [http://www.php.net/function.key]: Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key() [http://www.php.net/function.key]: Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key() [http://www.php.net/function.key]: Passed variable is not an array or object in /in/vuUhf on line 17 </li> <li> Warning: key() [http://www.php.net/function.key]: Passed variable is not an array or object in /in/vuUhf on line 17 </li> </ul> </body> </html>