For any queries you can reach us at infovistarindia@gmail.com / WhatsApp us: +919158876092

PHP foreach loop

Overview

The foreach loop is used to traverse the array elements. The foreach loop works only on arrays and is used to loop through each key/value pair in an array.

Syntax:

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

Example:

$colors = array("red", "green", "blue", "yellow", “orange”);
foreach ($colors as $value) {
  echo "$value <br>";
}