Prova così (anche se non sono sicurissimo):
Codice PHP:function HTMLOptions($menu, $sel_id ='', $parentid = 0, $depth = 0, $v = [])
{
$children=array();
$result = '';
foreach ($menu as $item) if ($item["parentid"] == $parentid)
$children[]=$item;
foreach ($children as $key => $child)
{
$symbol = '';
if ($depth > 0){
$symbol = str_repeat(' ',7);
for($i=0; $i < $depth -1; $i++ ){
if($v[$i +2] == 1){
$symbol .= '│'.str_repeat(' ',7);
}else{
$symbol .= str_repeat(' ',8);
}
}
$symbol .= (($key == (count($children)-1)) ? '└' : '├').'─ ';
}
$result .= '<option value="'.$child["id"].'" '.($child["id"]==$sel_id ? 'selected':'').'>'.$symbol.$child["title"].'</option>'."\n";
$v[$depth +1] = ($key == count($children) - 1) ? 0 : 1 ;
$result.=HTMLOptions($menu, $sel_id, $child["id"], $depth+1, $v);
}
return $result ? $result : null;
}

Rispondi quotando