PHP foreach Loop
The foreach loop statement only works with arrays and objects.
It will loop through an entire array, performing the specified actions for each value in the array.
PHP foreach Loop
<?php
$number[0] = "one";
$number[1] = "two";
$number[2] = "Three";
$number[4] = "four";
foreach ($number as $value) {
echo "$value";
}
?>
//OUTPUT
one
two
three
four
PHP foreach Loop Value
<?php
$num['one'] = "1";
$num['two'] = "2";
$num['three'] = "3";
foreach ($num as $key => $value) {
echo $value . " is a " . $key;
}
?>
//OUTPUT
one is a 1.
two is a 2.
three is a 3.