php using for each code example
Example 1: php foreach
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
Example 2: foreach in php
<?php
// Declare an array
$arr = array("green", "blue", "pink", "white");
// Loop through the array elements
foreach ($arr as $element) {
echo "$element ";
}
?>
Example 3: for each loop php
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>