The PHP for Loop
Syntax
for (init counter; test counter; increment counter) {
code to be executed;
}
Example
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
The PHP foreach Loop
Syntax
foreach ($array as $value) {
code to be executed;
}
Example
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
Syntax
for (init counter; test counter; increment counter) {
code to be executed;
}
Example
<?php
for ($x = 0; $x <= 10; $x++) {
echo "The number is: $x <br>";
}
?>
The PHP foreach Loop
Syntax
foreach ($array as $value) {
code to be executed;
}
Example
<?php
$colors = array("red", "green", "blue", "yellow");
foreach ($colors as $value) {
echo "$value <br>";
}
?>
Post a Comment