Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //PHP 5.3+
- echo array_reduce(
- ___$menu = array(
- ______array('home', 'Home'),
- ______array('news', 'News'),
- ______array('profile', 'Profile'),
- ______array('products', 'Products', array(
- _________array('webapp', 'Web Application', array(
- ____________array('php', 'PHP dan MySQL'),
- ____________array('rails', 'Ruby on Rails'),
- ____________array('nodejs', 'Node.js')
- _________)),
- _________array('deskapp', 'Desktop Application'),
- _________array('mobapp', 'Mobile Application')
- ______)),
- ______array('contact', 'Contact Us')
- ___), $cb = function($m, $i) use (&$cb) {
- ______$m .= "<li><a href=\"$i[0].php\">$i[1]</a>";
- ______if (isset($i[2]))
- _________$m .= array_reduce($i[2], $cb, "<ul>") . "</ul>";
- ______$m .= "</li>";
- ______return $m;
- ___}, "<ul>"
- ) . "</ul>";
- ?>
- <?php
- //PHP 5.3-
- $menu = array(
- ___array('home', 'Home'),
- ___array('news', 'News'),
- ___array('profile', 'Profile'),
- ___array('products', 'Products', array(
- ______array('webapp', 'Web Application', array(
- _________array('php', 'PHP dan MySQL'),
- _________array('rails', 'Ruby on Rails'),
- _________array('nodejs', 'Node.js')
- ______)),
- ______array('deskapp', 'Desktop Application'),
- ______array('mobapp', 'Mobile Application')
- ___)),
- ___array('contact', 'Contact Us')
- );
- function menu($m, $i) {
- ___$m .= "<li><a href=\"$i[0].php\">$i[1]</a>";
- ___if (isset($i[2]))
- ______$m .= array_reduce($i[2], 'menu', "<ul>") . "</ul>";
- ___$m .= "</li>";
- ___return $m;
- }
- echo array_reduce($menu, 'menu', "<ul>") . "</ul>";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement