I have a function generating nested navigation menu:
function recursive_foreach($array, $display) {
$out = '<ul>';
foreach ($array as $key => $value) {
...
$out .= '<li class="'. $is_active . $is_parent . '"><a href="' . $url . '">' . $value['name'] . '</a>'; }
if (is_array($value['has_children'])) {
$out .= recursive_foreach( ...
}
$out .= "</li>";
}
$out .= '</ul>';
return $out;
}
I want to add css class just to the first “ul” element. I know how to determine first element inside foreach loop but how can I get it outside of it?
Best pass an appropriate parameter: