📡 You're offline — showing cached content
New version available!
Quick Access
Tutorials PHP for Beginners Control Flow

Control Flow

7 min read Quiz at the end
Control flow lets PHP code make decisions and repeat actions. Use if/else to run code based on conditions and loops like for and foreach to repeat code. These are the core building blocks of any dynamic PHP application.

Conditional Statements

$score = 85;
if ($score >= 90) {
    echo "Grade: A";
} elseif ($score >= 70) {
    echo "Grade: B";
} else {
    echo "Grade: C";
}

Loops

// For loop
for ($i = 0; $i < 5; $i++) echo $i;

// Foreach
$fruits = ["apple","banana"];
foreach ($fruits as $f) echo $f;

// While
$n = 1;
while ($n <= 5) echo $n++;