note 58630 deleted from control-structures.foreach by googleguy
| From: | googleguy@php.net | Date: | Wed, 14 Nov 2012 22:33:46 +0000 |
| Subject: | note 58630 deleted from control-structures.foreach by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-191980@lists.php.net to get a copy of this message | ||
Note Submitter: janezr at jcn dot si
----
If you want to "look-ahead" values in an associative or non-continuous array, this might
help:
<?php
$myArray =
{'one'=>1,'two'=>2,'five'=>5,'three'=>3}
$all_keys = array_keys($myArray);
foreach ( $all_keys as $key_index => $key ) {
$value =& $myArray[$key];
// $all_keys[$key_index+2] gives null if we go past the array boundary - be carefull there
$value2 =& $myArray[$all_keys[$key_index+2]] ;
...
}
?>