note 90185 added to control-structures.foreach
| From: | timgolding_10 at hotmail dot com | Date: | Thu, 09 Apr 2009 09:50:18 +0000 |
| Subject: | note 90185 added to control-structures.foreach | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-152995@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 92.48.74.199
Probable Submitter: 82.153.163.251
----
Manual Page -- http://www.php.net/manual/en/control-structures.foreach.php
Edit -- https://master.php.net/note/edit/90185
Del: integrated -- https://master.php.net/note/delete/90185/integrated
Del: useless -- https://master.php.net/note/delete/90185/useless
Del: bad code -- https://master.php.net/note/delete/90185/bad+code
Del: spam -- https://master.php.net/note/delete/90185/spam
Del: non-english -- https://master.php.net/note/delete/90185/non-english
Del: in docs -- https://master.php.net/note/delete/90185/in+docs
Del: other reasons-- https://master.php.net/note/delete/90185
Reject -- https://master.php.net/note/reject/90185
Search -- https://master.php.net/manage/user-notes.php