Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views10 pages

PHP Control Flow Examples

Uploaded by

24pit004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

PHP Control Flow Examples

Uploaded by

24pit004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

PHP Control Flow Statements

With Code Examples


if Statement
• <?php
• $age = 20;
• if ($age >= 18) {
• echo "You are eligible to vote.";
• }
• ?>
if...else Statement
• <?php
• $number = 5;
• if ($number % 2 == 0) {
• echo "Even number";
• } else {
• echo "Odd number";
• }
• ?>
if...elseif...else Statement
• <?php
• $score = 85;
• if ($score >= 90) {
• echo "Grade A";
• } elseif ($score >= 75) {
• echo "Grade B";
• } else {
• echo "Grade C";
• }
switch Statement
• <?php
• $day = "Tuesday";
• switch ($day) {
• case "Monday":
• echo "Start of the week!";
• break;
• case "Tuesday":
• echo "Second day!";
• break;
while Loop
• <?php
• $i = 1;
• while ($i <= 5) {
• echo $i . " ";
• $i++;
• }
• ?>
do...while Loop
• <?php
• $j = 1;
• do {
• echo $j . " ";
• $j++;
• } while ($j <= 5);
• ?>
for Loop
• <?php
• for ($i = 1; $i <= 5; $i++) {
• echo "Number: $i<br>";
• }
• ?>
foreach Loop
• <?php
• $colors = ["Red", "Green", "Blue"];
• foreach ($colors as $color) {
• echo "$color<br>";
• }
• ?>
break and continue
• <?php
• for ($i = 1; $i <= 10; $i++) {
• if ($i == 5) continue;
• if ($i == 8) break;
• echo "$i ";
• }
• ?>

You might also like