I was trying to get the same result in two places with this code by including it with include(""); but after the first include goes right the second one gives me the last element of the array I made, the array is this one:
<?php
$aMenu = array(
array(
"title" => "Home",
"page" => "home",
),
array(
"title" => "Over mijzelf",
"page" => "mijzelf",
),
array(
"title" => "PC Games",
"page" => "games",
),
array(
"title" => "Video's maken",
"page" => "videos",
),
array(
"title" => "Basketball",
"page" => "basketball",
),
array(
"title" => "Fitness",
"page" => "fitness"
),
array(
"title" => "Toekomst",
"page" => "toekomst"
),
);
I call it here
foreach($aMenu as $aMenu) {
$sClass = '';
if ($aMenu["page"] == $_GET['page']) {
$sClass = 'class = "active" ';
}
/*echo $aMenu["title"];
echo $aMenu["page"];*/
echo '
<ul class=" nav nav-pills nav-stacked">
<li class="'.$sClass.'" role="presentation" ><a href="index.php?page='.$aMenu["page"].'">'.$aMenu["title"].'</a></li>
</ul>';
}
You overwrite your array while iterating:
foreach($aMenu as $aMenu)
Write something like this
foreach($aMenu as $entry)
so your iteration variable won't overwrite the array itself.