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 "<ul>";
$oldvalue = null;
foreach($input as $value){
if($oldvalue != null && !is_array($value))
echo "</li>";
if(is_array($value)){
ToUl($value);
}else
echo "<li>" + $value;
$oldvalue = $value;
}
if($oldvalue != null)
echo "</li>";
echo "</ul>";
}
[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 "<ul>";
foreach($input as $value)
if(is_array($value)){
echo "<li>";
ToUl($value);
echo "</li>";
}else
echo "<li>" + $value + "</li>";
echo "</ul>";
}