Here is the commented version of the two scripts above:
In both, assume that $ar1 is the first array, and $ar2 is the second array.
echo $ar1[$n].$ar2[$n]; means echo the value of that part of the first array, then that part of the second array. You could place them into links as you wish.
PHP Code:
for ($n=0; isset($ar1[$n]) && isset($ar2[$n]; $n++) { //for loop:
//set $n to zero first time
//while both the $ar1 and $ar2 at $n are set, like $ar2[7], etc.
echo $ar1[$n].$ar2[$n];
}
PHP Code:
$n=0; //start counting at 0, like array counters do.
foreach ($ar1 as $thing) { //for each value of $ar1
$bigar[$n][1] = $thing; //set $bigarray at $n at 1 to that part
$n++; //add one to $n, continue
}
$n=0; //repeat for array 2
foreach ($ar2 as $thing) {
$bigar[$n][2] = $thing; //now use the 2 value of the array
$n++;
}
foreach ($bigar as $part) { //go through each chunk of the array
echo $part[1].$part[2]; //now, like above, that part has [1], and [2]
}
Basically, this one combines both arrays into a master, bigger array, then runs through a foreach loop of that, then echoes the inner bits of that array.
Note: I also fixed a typo above. I put $ar1/$ar2 in the foreach loop, but I meant $thing.
Bookmarks