This is my array:
array(1) {
["farm"]=>
array(1) {
["animals"]=>
array(1) {
[horses]=>
array(4) {
["fred.jpg"]=>
string(63) "farm/animals/horses/fred.jpg"
["sam.jpg"]=>
string(74) "farm/animals/horses/sam.jpg"
["alan.jpg"]=>
string(64) "farm/animals/horses/alan.jpg"
["john.jpg"]=>
string(63) "farm/animals/horses/john.jpg"
}
}
}
}
I want to convert it to a ul list, so the result should be:
<ul>
<li>farm
<ul>
<li>animals
<ul>
<li>horses
<ul>
<li>fred.jpg</li>
<li>sam.jpg</li>
<li>alan.jpg</li>
<li>john.jpg</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
I used this function:
function array2ul($array) {
$output = '<ul>';
foreach ($array as $key => $value) {
$function = is_array($value) ? __FUNCTION__ : 'htmlspecialchars';
$output .= '<li>' . $key . '</li>';
}
return $output . '</ul>';
}
But the result is:
<ul>
<li>farm
<ul>
<li>animals
<ul>
<li>horses
<ul>
<li>fred.jpg</li>
<li>farm/animals/horses/sam.jpg</li>
<li>farm/animals/horses/alan.jpg</li>
<li>farm/animals/horses/john.jpg</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>