I have the following array which I want to transform into an unordered list (HTML).
Array
(
[0] => Array
(
[url] => /
[
Try a function like this:
function ToUl($input){
echo "";
$oldvalue = null;
foreach($input as $value){
if($oldvalue != null && !is_array($value))
echo "";
if(is_array($value)){
ToUl($value);
}else
echo "- " + $value;
$oldvalue = $value;
}
if($oldvalue != null)
echo "
";
echo "
";
}
[Edit]
I'll leave the function which creates a li
for every array, which is simpler, in case any reader needs it:
function ToUl($input){
echo "";
foreach($input as $value)
if(is_array($value)){
echo "- ";
ToUl($value);
echo "
";
}else
echo "- " + $value + "
";
echo "
";
}