note 90388 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:28:43 +0000 |
| Subject: | note 90388 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191965@lists.php.net to get a copy of this message | ||
Note Submitter: strata_ranger at hotmail dot com
----
Note that foreach() iterates through an array in the same order that its elements were defined. If
you want to iterate through an array in a different order, you will need to sort the array prior to
entering the loop.
For example:
<?php
// Iterate through an array in reverse order,
// maintaining key association (i.e. for associative arrays)
foreach(array_reverse($array, true) as $key=>$value)
{
. . .
}
?>