3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $items = array( "Home", "Pages" => array( "About", "Services", "Products", "Contact", "Column Layouts" => array( "1 Column", "2 Column (Left Sidebar)", "2 Column (Right Sidebar)", "3 Column", "4 Column" ), "FAQs", "Sitemap", "Privacy Policy" ) ); function getMenu($array) { foreach($array as $key => $value) { if(is_array($value)) { echo "<li>" . $key . "</li>"; echo "<ul>"; getMenu($value); echo "</ul>"; } else { echo "<li>" . $value . "</li>"; } } } echo "<ul>"; getMenu($items); echo "</ul>";
Output for 4.3.0 - 7.1.0
<ul><li>Home</li><li>Pages</li><ul><li>About</li><li>Services</li><li>Products</li><li>Contact</li><li>Column Layouts</li><ul><li>1 Column</li><li>2 Column (Left Sidebar)</li><li>2 Column (Right Sidebar)</li><li>3 Column</li><li>4 Column</li></ul><li>FAQs</li><li>Sitemap</li><li>Privacy Policy</li></ul></ul>