-
-
-
Foreach loop
Syntax foreach ($array as $key => $value) { code to be executed; } PHP Code Sample <?php $colors = array ( “red”, “green”, “blue”, “yellow” ); foreach ($colors as $value) { echo “$value <br>”; } ?>
-
Do While loop
Syntax do { code to be executed; } while (condition is true); PHP Code Sample <?php $x = 1 ; do { echo “The number is: $x”; $x++; } while ($x <= 5 ); ?>
-
While loop
Syntax while (condition is true) { code to be executed; } PHP Code Sample <?php $x = 1 ; while ($x <= 5 ) { echo “The number is: $x”; $x++; } ?>
-
For loop
Syntax for (init counter; test counter; increment counter) { code to be executed for each iteration; } PHP Code Sample <?php for ($x = 0; $x <= 10; $x++) { echo “The number is: $x”; } ?>
-
If statement
Syntax if (condition) { code to be executed if condition is true; } PHP Code Sample <?php $t = date( “H” ); if ($t < “20” ) { echo “Have a good day!”; } ?> Syntax if (condition) { code to be executed if condition is true; } else { code to be executed if […]