Way too complicated a function. Something along these lines does it:
function treeList(array $data) {
$list = ''
;
foreach ($data as $item) {
$list .= '' ;
$list .= $item['name'];
if (!empty($item['children'])) {
$list .= treeList($item['children']);
}
$list .= '';
}
$list .= '';
return $list;
}
$data = array(
array(
'name' => 'Foo',
'children' => array(
array(
'name' => 'Bar'
)
)
)
);
echo treeList($data);
manpreet
Best Answer
3 years ago
I am using this function to display UL list:
The
$arResultcontains a tree like this:The above function prints everything under
Electronics->Tvwhile the truth is that underElectronicsthere should beTV, Video, Mobile Laptop, Other..This function somehow is putting
ul liin incorrect mode.The Array Dump is here: