Traversing Arrays Using list() and each() in PHP
By Andi, Stig and Derick Viewed: 31761 times Emailed: 182 times Printed: 189 times
Although foreach() is the nicer way of iterating over an array, an additional way of traversing an array is by using a combination of the list() construct and the each() function:
$players = array("John", "Barbara", "Bill", "Nancy");
reset($players);
while (list($key, $val) = each($players)) {
print "#$key = $val\n";
}
The output of this example is
#0 = John
#1 = Barbara
#2 = Bill
#3 = Nancy
Comments(0)
Be the first one to add a comment
Latest Tutorials
More Latest News
Most Viewed Articles (in last 30 days)

