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
2 years ago
I am using this function to display UL list:
The
$arResult
contains a tree like this:The above function prints everything under
Electronics->Tv
while the truth is that underElectronics
there should beTV, Video, Mobile Laptop, Other
..This function somehow is putting
ul li
in incorrect mode.The Array Dump is here: