
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Multiple Index Variables in PHP foreach Loop
The ‘foreach’ loop can be used to multiple index variables of two arrays. This has been shown below −
Example
<?php $FirstArray = array('aB', 'PQ', 'cd', 'pm'); $SecondArray = array('12', '34', '90', '49'); foreach($FirstArray as $index => $value) { echo $FirstArray[$index].$SecondArray[$index]; echo "<br/>"; } ?>
Output
This will produce the following output −
aB12 PQ34 cd90 pm49
Note − If there are more than 2 arrays, nested ‘foreach’ loops can be used.
Here, 2 arrays have been declared and they are being traversed using the ‘foreach’ loop. The result is that the respective index of every array is matched and the data at those indices are displayed one next to the other.
Advertisements