Pages

The foreach Loop

The foreach Loop

The foreach loop is used to loop through arrays.

 

Syntax

foreach ($array as $value)
  {
  code to be executed;
  } 

Example

The following example demonstrates a loop that will print the values of the given array:
<html>
<body>

<?php
$x=array("one","two","three");
foreach ($x as $value)
  {
  echo $value . "<br>";
  }
?>

</body>
</html> 
Output:

one
two
three

No comments:

Flag Counter
| Copyright © 2013 Remote Tutor