For Loops in PHP

 

For loops execute the code number of times.:

The if statement executes some code if a condition is true .

for (init number; test number; increment number)
{
  code to be executed;
}
<?php
for ($x = 0; $x <= 10; $x++) {
    echo "The number is: $x 
"; } ?>

The PHP foreach Loop:

The foreach loop used only print arrays values , and is used to loop through each key/value pair in an array.

foreach ($array as $value){
  code to be executed;
}
<?php
$arr = array(1, 2, 3, 4);

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