PHP syntax: iterate over an array

Contributor Icon Contributed by qmchenry  
Tag Icon Tagged: PHP programming  

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;

 

1 Comment -


  1. MAc Mold said on October 19, 2011

    This does work with me
    following error is shown

    Error description Invalid argument supplied for foreach()

    My Syntax
    foreach($amountarray as $v)
    {
    Print $v;
    }

 

RSS feed for comments on this post. TrackBack URL

Leave a comment -