[eluser]Unknown[/eluser]
Hi Again, This little function loops though a multidimensional array and echos the data out as a multilevel list. It works a treat but instead of echoing the HTML list i would like it to return the HTML i have tried with a snippet below but it doesn't display the menu correctly.
Code that works fine.
Code:
/*
* Render Cats into list.
*************************/
function renderCatsList($arr)
{
echo "<ul>";
foreach ($arr as $cat)
{
echo "<li>";
if(!isset($cat['children'])) $cat['children'] = array();
echo $cat['cat_title'];
if (count($cat['children']) > 0)
{
$this->renderCatsList($cat['children']);
}
echo "</li>";
}
echo "</ul>";
}
But i would prefer this method but this does not work.
Code:
/*
* Render Cats into list.
*************************/
function renderCatsList($arr)
{
$output = "<ul>";
foreach ($arr as $cat)
{
$output .= "<li>";
if(!isset($cat['children'])) $cat['children'] = array();
$output .= $cat['cat_title'];
if (count($cat['children']) > 0)
{
$this->renderCatsList($cat['children']);
}
$output .= "</li>";
}
$output .= "</ul>";
return $output;
}
Regards Script Gecko :coolmad: