I have put together a menu using a md array, but I am having problems getting the sub menu items to print out properly.
I use this to build the menus:
class Language {
public $langCode ;
function __construct($code)
{
$this->langCode = $code ;
}
public function navigation()
{
if($this->langCode == 'en')
{
$menu = array(
array('Home', ''),
array('Galleries', '',
array('Top ten hottest' => 'hottest.php'),
array('Top ten worst' => 'hottest.php'),
),
array('Upload', 'upload.php'),
array('Login/register', ''),
array('Resources', '',
array('News' => ''),
array('What\'s a mound?' => ''),
array('Legal' => ''),
array('Links' => ''),
),
array('abc?', ''),
) ;
}
return $menu ;
}
}
And I am trying to build the menu using:
$mainMenu = $lng->navigation() ;
echo "<ul>\n" ;
foreach($mainMenu as $set) {
$x = 0 ;
echo "<li><a href='".$set[1]."'>".$set[0]."</a></li>\n" ;
if($set[2])
{
foreach($set[2] as $label => $item) {
echo $item ;
}
}
}
But all I’m getting is the first item from the sub menu from the foreach loop which makes no sense to me because I can access it directly by doing $set[2][0] (before I assigned keys to the values in the arrays).
What do I need to do to get the output I want?
You are forgetting to make set[2] an array. Right now you have set[2] and set[3] and on resources you have set[4] and set[5] also: