wJesus56 Posted January 26, 2022 Share Posted January 26, 2022 (edited) I'm trying to make a low-level multi-level menu from PHP array . I use lists to make the menu drop-down. I use a function to bring an array to a list, but the function I use has a problem with generating links to menu items. Is there anyone here who could help with the refinement of the function? Example: link to bigbanans in cats2 must be: cat2/items2/banans/bigbanans <!DOCTYPE html> <html> <head> <title>jQuery Slideshow - sjoloughlin</title> <meta charset="utf-8"> <style> nav ul { list-style: none; padding: 0; text-align:center; } nav li { background-color: rgba(0,100,0,0.5); position: relative; display: inline-block; } nav li:hover { background-color: rgba(100,0,0,0.5) } nav a { display:block; padding: 0.5em; text-decoration: none; color: rgba(0,0,100,0.9); } nav ul ul { display: none; position: absolute; } nav li:hover > ul { display: block; } nav ul ul ul { left: 100%; top: 0; } nav > ul > li > ul > li { min-width: 100%; } </style> </head> <?php function is_multidimensional(array $array) { return count($array) !== count($array, COUNT_RECURSIVE); } function printArrayList($array, $last) { $pathstring =""; echo "<ul>\n"; $path=$last; foreach ($array as $k => $v) { if (strpos($k, "option")=="") { $path[]= $k; } $fullpath= implode("/", $path); if (is_array($v)) { echo "<li><a href=".$fullpath.">".$k."</a>\n"; if (is_multidimensional($v)) { printArrayList($v, $path); } else { // unset($path); $path=array(); } continue; } if (strpos($k, "option")>0) { } else { echo "<li>" . $k . " " . $v . ""; } // } else { echo "<li>" . $k . " " . $v . "</li>"; } } echo "</ul>\n"; } $menu = array( 'Cat1' => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "ITEMS1" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "Apples" => array( 'FORCATEGORY_NUMBER1_option' => "111", 'FORCATEGORY_NUMBER2_option' => "2", ), "Banans" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), ), "ITEMS2" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "Apples" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), "Banans" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), ), ) , 'Cat2' => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "ITEMS1" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "Apples" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), "Banans" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), ), "ITEMS2" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", 'FORCATEGORY_NUMBER3_option' => "3", "Apples" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), "Banans" => array( 'FORCATEGORY_NUMBER1_option' => "1", 'FORCATEGORY_NUMBER2_option' => "2", ), ), ) , ); ?> <body> <nav> <?PHP printArrayList($menu, $last=array()); ?> </nav> </body> </html> Edited January 26, 2022 by wJesus56 Quote Link to comment https://forums.phpfreaks.com/topic/314462-is-anybody-know-how-to-make-a-correct-linksfull-path-to-categories-in-case-with-multimenu-below/ Share on other sites More sharing options...
ginerjm Posted January 26, 2022 Share Posted January 26, 2022 We generally use the <> icon to create a box to hold the Code, not the written text that explains your topic. Makes it much easier to read not only the code (in the box) but the text NOT in the box. Having to scroll left and write to simply read is a pia and not worth doing. Quote Link to comment https://forums.phpfreaks.com/topic/314462-is-anybody-know-how-to-make-a-correct-linksfull-path-to-categories-in-case-with-multimenu-below/#findComment-1593623 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.