The following code shows a multi-dimensional array, and a function that loops through the array to echo out a nested menu with links.
However, the function doesn't appear to be working as nothing is being echoed.
It was working but I have changed a few includes around, so could it be something to do with that?
<?php
$urls = array (
0=>array (
0=>"Home",
1=>"http://uni.michaelnorris.co.uk/",
2=>"Home",
3=>"",
4=>"",
5=>"1"
),
1=>array (
0=>"Blog",
1=>"http://uni.michaelnorris.co.uk/blog/",
2=>"Blog",
3=>"",
4=>"",
5=>"1"
),
2=>array (
0=>"Glossary",
1=>"http://uni.michaelnorris.co.uk/",
2=>"Glossary",
3=>"",
4=>"",
5=>"1"
),
3=>array (
0=>"Resources",
1=>"http://uni.michaelnorris.co.uk/blog/",
2=>"Resources",
3=>"",
4=>"",
5=>"1"
),
4=>array (
0=>"Staff",
1=>"http://uni.michaelnorris.co.uk/",
2=>"Staff",
3=>"",
4=>"",
5=>"1"
),
5=>array (
0=>"Blog",
1=>"http://uni.michaelnorris.co.uk/blog/",
2=>"Blog",
3=>"",
4=>"",
5=>"1"
),
6=>array (
0=>"Home",
1=>"http://uni.michaelnorris.co.uk/",
2=>"Home",
3=>"",
4=>"",
5=>"1"
),
7=>array (
0=>"Blog",
1=>"http://uni.michaelnorris.co.uk/blog/",
2=>"Blog",
3=>"",
4=>"",
5=>"1"
)
);
function showMenu()
{
$top = count($urls);
echo "<ul>";
for ($i=0;$i<$top;$i++) {
echo "<li><a href='".$urls[$i][1]."' title='".$urls[$i][2]."'>".$urls[$i][0]."</a><li>";
}
echo "</ul>";
}
?>
<?php showMenu(); ?>
error_reporting(E_ALL);=> Notice: Undefined variable: urls in x.php on line 81