note 90185 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:29:02 +0000 |
| Subject: | note 90185 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191966@lists.php.net to get a copy of this message | ||
Note Submitter: timgolding_10 at hotmail dot com
----
Here's an example where one can loop through two or more arrays in one loop. this example has
two arrays.
<?php
$array1=array("a", "b", "c");
$array2=array("1", "2", "3");
foreach(array_merge($array1, $array2) as $value)
{
echo $value;
}
// abc123
?>
For more arrays just add them as additional arguments to the array_merge function. This example
isn't very useful if your loop needs to return the keys for numeric indexed arrays. For
associative arrays you can return the key however must be certain that all the indexes are unique
across all arrays.