note 58630 modified in control-structures.foreach by danbrown

From: Date: Tue, 28 Apr 2009 13:07:27 +0000
Subject: note 58630 modified in control-structures.foreach by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-153917@lists.php.net to get a copy of this message
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]] ; ... } ?> --was-- If you want to "look-ahead" values in an associative or non-continuous array, this might help: <? $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]] ; ... } ?> http://php.net/manual/en/control-structures.foreach.php

« previous php.notes (#153917) next »