$arr = array(
0 => '3,6',
3 => '4,5',
4 => '7,8',
8 => '9',
);
function writeList($items){
global $arr;
echo '<ul>';
$items = explode(',', $items);
foreach($items as $item){
echo '<li>'.$item;
if(isset($arr[$item]))
writeList($arr[$item]);
echo '</li>';
}
echo '</ul>';
}
writeList($arr[0]);
Проверьте это.
или
$arr = array(
3 => array(
4 => array(
7 => null,
8 => array(
9 => null
),
),
5 => null,
),
6 => null,
);
function writeList($items){
if($items === null)
return;
echo '<ul>';
foreach($items as $item => $children){
echo '<li>'.$item;
writeList($children);
echo '</li>';
}
echo '</ul>';
}
writeList($arr);