Sitemap
Sahirullah

Sahirullah

Be learn Anywhere anytime.

Member-only story

PHP Control flow

2 min readNov 14, 2025

--

⚙️ What Is “Control Flow”?

Control Flow means telling PHP what to do next —
just like giving step-by-step instructions to a robot 🤖.

It helps your code:

  • make decisions (yes/no, true/false)
  • repeat actions (loops)
  • choose between options

🧩 1. Conditional Statements

These help PHP decide what to do.

🟢 if Statement

👉 Tells PHP to do something if a condition is true.

$age = 18;
if ($age >= 18) {
echo "You can vote!";
}

🧠 Output:
✅ “You can vote!” (because 18 ≥ 18)

🟠 if...else

👉 Adds another path if the condition is not true.

$age = 16;
if ($age >= 18) {
echo "You can vote!";
} else {
echo "Sorry, you’re too young!";
}

🧠 Output:
❌ “Sorry, you’re too young!”

🔵 if...elseif...else

👉 Check multiple conditions.

$marks = 75;
if ($marks >= 80) {
echo "Grade A";
} elseif ($marks >= 60) {
echo "Grade B";
} else {
echo "Grade C";
}

--

--