I have two arrays first one is student name and the second one is his favorite author sekection as follows
$student array is as follows
array (size=3)
0 => string 'Jane' (length=4)
1 => string 'Michelle' (length=8)
2 => string 'Mark' (length=4)
Now the second array Author $selection is as follows:
array (size=3)
0 =>
array (size=3)
0 => string 'Mark Twaine' (length=11)
1 => string 'E A Poe' (length=7)
2 => string 'James Joyce' (length=11)
1 =>
array (size=3)
0 => string 'Oscar' (length=11)
1 => string 'Leo Toby' (length=7)
2 => string 'James Joyce' (length=11)
2 =>
array (size=3)
0 => string 'Leo Toby' (length=11)
1 => string 'E A Poe' (length=7)
2 => string 'James Joyce' (length=11)
Now I want to display the student name and his favorite authors i.e, Jane favorite authors are Mark Twaine, E A Poe, James Joyce and Michelle favorite authors are Oscar, Leo Toby, James Joyce and Mark favorite authors are Leo Toby, E A Poe, James Joyce ...
I have tried this so far
foreach( $student as $key => $val ) {
echo $val." read ";
foreach( $selection as $key1 ) {
foreach ($key1 as $key2 => $val2){
echo $val2;
echo ' and ';
}
echo "<br/>";
}
and getting this as output
Jane favorite is Mark Twaine and E A Poe and James Joyce and
Oscar and Leo Toby and James Joyce and
Leo Toby and E A Poe and James Joyce and
Michelle favorite is Mark Twaine and E A Poe and James Joyce and
Oscar and Leo Toby and James Joyce and
Leo Toby and E A Poe and James Joyce and
Mark favorite is Mark Twaine and E A Poe and James Joyce and
Oscar and Leo Toby and James Joyce and
Leo Toby and E A Poe and James Joyce and
Instead of
Jane favorite is Mark Twaine and E A Poe and James Joyce
Michelle favorite is Oscar and Leo Toby and James Joyce
Mark favorite is Leo Toby and E A Poe and James Joyce
I want foreach loop to restrict to only one single array value with incrementing key