Thursday, November 21, 2024
HomeWeb application programmingPHP programmingPHP syntax: iterate over an array

PHP syntax: iterate over an array

Given the array:

$ar = array("one", "two", "three", "four", "five");

The third element in the array can be accessed with:

echo $ar[3];

The following code will step through the array one element at a time and print each element:

foreach ($ar as $a)
echo $a;

Quinn McHenry
Quinn McHenry
Quinn was one of the original co-founders of Tech-Recipes. He is currently crafting iOS applications as a senior developer at Small Planet Digital in Brooklyn, New York.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

LATEST REVIEWS

Recent Comments

error: Content is protected !!