3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $source=json_decode('[{"name":"item 1"},{"name":"item 2"},{"name":"item 3","children":[{"name":"item 4"},{"name":"item 5"},{"name":"item 6","children":[{"name":"item 7"},{"name":"item 8"}]}]},{"name":"item 9"},{"name":"item 10"},{"name":"item 11"}]',true); function buildNestedList(array $a) { if(empty($a["name"])) { echo "\n<ol>\n"; foreach($a as $item) { buildNestedList($item); } echo "</ol>\n"; } else { echo "\t<li><div>".$a["name"]."</div>"; if(!empty($a["children"])) { buildNestedList($a["children"]); } echo "</li>\n"; } } buildNestedList($source);
Output for 5.2.0 - 5.6.28, hhvm-3.10.0 - 3.13.2, 7.0.0 - 7.1.0
<ol> <li><div>item 1</div></li> <li><div>item 2</div></li> <li><div>item 3</div> <ol> <li><div>item 4</div></li> <li><div>item 5</div></li> <li><div>item 6</div> <ol> <li><div>item 7</div></li> <li><div>item 8</div></li> </ol> </li> </ol> </li> <li><div>item 9</div></li> <li><div>item 10</div></li> <li><div>item 11</div></li> </ol>
Output for 5.1.0 - 5.1.6
Fatal error: Call to undefined function json_decode() in /in/trFpp on line 2
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_ARRAY, expecting '&' or T_VARIABLE in /in/trFpp on line 4
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_ARRAY, expecting ')' in /in/trFpp on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_ARRAY, expecting ')' in /in/trFpp on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/trFpp on line 4
Process exited with code 255.