Array element order and foreach() : foreach « Statement « PHP






Array element order and foreach()

 
<?
$letters[0] = 'A';
$letters[1] = 'B';
$letters[3] = 'D';
$letters[2] = 'C';

foreach ($letters as $letter) {
    print $letter;
}
?>
  
  








Related examples in the same category

1.Foreach Demo
2.Looping through an Enumerated Array
3.Iterating through a multidimensional array with foreach()
4.Modifying an array with foreach()
5.Using foreach() to Iterate Through an Array
6.Using foreach() with numeric arrays
7.Displaying the contents of an array using a loop
8.Iterating Through Object Properties
9.Implementing the traversable Iterator