I have seen so many examples but wasn't able to find an exact answer. Most of the question answered either have errors of are not answered properly. If anyone knows of a finished solution similar to my question, please point me in that direction!
$menu = Array
(
[dashboard] => Array
(
[main] => /phone/summary
[main_selected] => 1
[child_selected] =>
[children] => Array
(
[phones] => /phones
[tablets] => /tablets
)
)
[mobile templates] => Array
(
[main] => /phone/templates
[main_selected] =>
)
[phone size] => Array
(
[main] => link_3
[main_selected] =>
[child_selected] =>
[children] => Array
(
[iphone] => /phone/iphone_size
[samsung] => /phone/samsung_size
[android] => /phone/android_size
[blackberry] => /phone/blackberry_size
[google_pixels] => /phone/google_phone_size
)
)
[phone chart] => Array
(
[main] => /phone/charts/
[main_selected] =>
)
)
And here is what I would like to turn it into:
<ul>
<li><a href="">Dashboard<a/>
<ul>
<li><a href="/phones">Iphone</a></li>
<li><a href="/tablets">Tablets</a></li>
</ul>
</li>
<li><a href="/phone/templates">mobile templates<a/>
</li>
<li><a href="link_3">phone size<a/>
<ul>
<li><a href="/phone/iphone_size">Iphone</a></li>
<li><a href="/phone/samsung_size">Samsung</a></li>
<li><a href="/phone/android_size">Android</a></li>
<li><a href="/phone/blackberry_size">Blackberry</a></li>
<li><a href="/phone/google_phone_size">Google_pixels</a></li>
</ul>
</li>
<li><a href="/phone/charts/">phone chart<a/></li>
</ul>
Hope someone understands what is displayed. This is what I have tried. Sure it's not very great.
public function sideMenu($actions, $level = 0)
{
$xhtml = '';
$main_menu = null;
$ret = "";
$test = "";
foreach ($actions as $key => $value)
{
if(isset($value['children']))
{
$main_menu .= "<li>".$key."<li>";
//print_r($main_menu);
if (is_array($value["children"]))
{
$ret .= "<ul>";
$test = $value["children"];
foreach ($test as $k1 => $v1)
{
$ret .= "<li> ".$k1." </li>";
}
$ret .= "</ul>";
print_r($ret);
}
}
else
{
$main_menu .= "<li>".$key."</li>";
}
}
return $xhtml;
}