Advertisement
cdsatrian

menu generator

May 2nd, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.49 KB | None | 0 0
  1. <?php
  2. //PHP 5.3+
  3. echo array_reduce(
  4. ___$menu = array(
  5. ______array('home', 'Home'),
  6. ______array('news', 'News'),
  7. ______array('profile', 'Profile'),
  8. ______array('products', 'Products', array(
  9. _________array('webapp', 'Web Application', array(
  10. ____________array('php', 'PHP dan MySQL'),
  11. ____________array('rails', 'Ruby on Rails'),
  12. ____________array('nodejs', 'Node.js')
  13. _________)),
  14. _________array('deskapp', 'Desktop Application'),
  15. _________array('mobapp', 'Mobile Application')
  16. ______)),
  17. ______array('contact', 'Contact Us')
  18. ___), $cb = function($m, $i) use (&$cb) {
  19. ______$m .= "<li><a href=\"$i[0].php\">$i[1]</a>";
  20. ______if (isset($i[2]))
  21. _________$m .= array_reduce($i[2], $cb, "<ul>") . "</ul>";
  22. ______$m .= "</li>";
  23. ______return $m;
  24. ___}, "<ul>"
  25. ) . "</ul>";
  26. ?>
  27.  
  28. <?php
  29. //PHP 5.3-
  30. $menu = array(
  31. ___array('home', 'Home'),
  32. ___array('news', 'News'),
  33. ___array('profile', 'Profile'),
  34. ___array('products', 'Products', array(
  35. ______array('webapp', 'Web Application', array(
  36. _________array('php', 'PHP dan MySQL'),
  37. _________array('rails', 'Ruby on Rails'),
  38. _________array('nodejs', 'Node.js')
  39. ______)),
  40. ______array('deskapp', 'Desktop Application'),
  41. ______array('mobapp', 'Mobile Application')
  42. ___)),
  43. ___array('contact', 'Contact Us')
  44. );
  45. function menu($m, $i) {
  46. ___$m .= "<li><a href=\"$i[0].php\">$i[1]</a>";
  47. ___if (isset($i[2]))
  48. ______$m .= array_reduce($i[2], 'menu', "<ul>") . "</ul>";
  49. ___$m .= "</li>";
  50. ___return $m;
  51. }
  52. echo array_reduce($menu, 'menu', "<ul>") . "</ul>";
  53. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement