How to use multiple arrays in " single " foreach() loop

arrays, echo, foreach, php

Solution

assume you have the same number of items in those two arrays.

if you want to use `foreach()`, then the arrays need to have the same index:

foreach ($a as $index => $value)
{
    echo $a[$index] .' '. $b[$index];
}

if the arrays have numeric index, you can just use `for()`:

for ($i = 0; $i < sizeof($a); $i++)
{
    echo $a[$i] .' '. $b[$i];
}

Problem

I'm trying to echo out all variables of two arrays with a single foreach loop making a url. Some coding examples will be honored. I have this so far : ``` <?php foreach($menu_names as $menu_name){ echo "<li><a href='?subj= " .urlencode($subjects["id"]). " '>".$menu_name."</a></li>"; } ?> ``` I want to add one more array within this loop

Original source

Related problems