$age = 18;
$country = 'BD';
// If - else
if($age==18){
echo 'You are Just Eligible';
}
elseif(age>=18){
echo 'You are Eligible';
}
else{
echo 'You are Not Eligible';
}
// Nested If - Else
if($country=='BD'){
if($age==18){
echo 'You are Just Eligible';
}
else{
echo 'You are Not Eligible';
}
}
else{
echo 'You are Not From BD;
}
// Double Condition inside a If using and( && ) , Or ( || ).
1.
if($age=='18' and $country=='BD'){
echo 'Allowed';
}
else{
echo 'Not Allowed';
}
2.
if($age=='18' || $country=='BD'){
echo 'Allowed';
}
else{
echo 'Not Allowed';
}
// Grater then Or Less then Condition
if($age>=18 and $age<=25){
echo 'You are Just Eligible';
}
else{
echo 'You are Not Eligible';
echo 'You are Just Eligible';
}
else{
echo 'You are Not Eligible';
}
Shortcut if else in one line
echo ($age == 18 ? "Eligible ": "Not Eligible" );
here $age == 18 ? "Eligible " means:
if($age ==18){
echo 'Eligible';
}
And : "Not Eligible" means:
else{
echo 'Not Eligible';
}
Nested Shortcut if else in one line
echo ($age == 18 ? $country == "BD" ? "Eligible ": "Not Eligible" );
//Switch Case
Switch($country){
case 'NZ ':
echo 'Not Permitted ';
break;
case 'IND':
echo 'Not Permitted ';
break;
case 'BD':
echo 'Permitted ';
break
default:
echo 'Enter a Valid value';
break;
}
// str_replace
0 Comments