Programming Tutorials

Traversing Arrays Using list() and each() in PHP

By: Andi, Stig and Derick in PHP Tutorials on 2008-11-22  

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");
while (list($key, $val) = each($players)) {
print "#$key = $val\n";

The output of this example is

#0 = John
#1 = Barbara
#2 = Bill
#3 = Nancy

Add Comment

* Required information


No comments yet. Be the first!

Most Viewed Articles (in PHP )

Latest Articles (in PHP)