PHP Foreach Loop

Loops through a block of code for each element in an area.

Syntax

<?php
foreach ($array as $value) {
  code to be executed;
} 
?>

Example

The following example will output the values of the given array ($colors):

<?php
$colors = array("yellow", "green", "blue", "golden");

foreach ($colors as $value) {
  echo "$value 
"; } ?>

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

*