🟡 Control Flow · Lesson 07
If-Else and Switch
If-Else and Switch
Decision Making
PHP uses
if, elseif, else and switch to make decisions.if-elseif-else
<?php
$marks = 82;
if ($marks >= 90) {
echo "A+";
} elseif ($marks >= 33) {
echo "Pass";
} else {
echo "Fail";
}
?>Pass
switch
<?php
$day = "Mon";
switch ($day) {
case "Mon": echo "Monday"; break;
case "Tue": echo "Tuesday"; break;
default: echo "Other";
}
?>Monday
Summary
- if/elseif/else choose by condition; switch chooses by value.
- Always add
breakin switch cases.
Decision Making
PHP decisions के लिए
if, elseif, else और switch use करती है।if-elseif-else
<?php
$marks = 82;
if ($marks >= 90) {
echo "A+";
} elseif ($marks >= 33) {
echo "Pass";
} else {
echo "Fail";
}
?>Pass
switch
<?php
$day = "Mon";
switch ($day) {
case "Mon": echo "Monday"; break;
case "Tue": echo "Tuesday"; break;
default: echo "Other";
}
?>Monday
सारांश
- if/elseif/else condition से चुनते हैं; switch value से।
- switch cases में हमेशा
breakलगाएं।