<?php
foreach($menu_names as $menu_name){
$i=0;
echo "<li><a href='?subj=" .$subjects_ids[$i]. " '>".$menu_name."</a></li>";
$i++;
}
?>
$subjects_ids is an array which contains three values of 1, 2 and 3. But the link created here in HTML only contains ?subj=3 for all three $menu_name. The first $menu_name should have subj=1 and second should have 2 and third should have 3.
place
$i=0;outside of the loop.Explanation:
when you place
$ivariable inside the foreach loop and set it’s value to0. every time the data is looped value of$iwill be set to $i=0; hence you should place it on outside the foreach loop.