🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

How to declare conditional statements in PHP with example?

When You write a code different actions for different conditions. Then, You can use Conditional statements in your code to do this.

If Statement:-
If Statement executes some code when one condition is true.
ex:-

<?php
$a = 5;
if ($a < 6) {
echo "Have a good day!";
}
//Second example
if(15<19) //
{
echo "condition is true <br>";
}
else {
echo "this is true <br>";
}
echo "this is last <br>";
?>

If …else Statement:-
If …. else Statement executes similar if statement when one condition is true and another condition is false.
ex:-

<?php
$a = 4;
if ($a < 1) {
echo "This is True"; //check statement if right then print if wrong then next
} else {
echo "This is False <br>";
}
//second example
$a = 4;
if ($a < 6) {
echo "This is True!";
} else {
echo "This is False";
}
?>

If…elseif…else Statement:-
If…elseif…else Statement executes different codes when for more than than two or multiple codes.
ex:-

<?php
//elseif statement
if(5>7)
{
echo "this is wrong"; //check statement if right then print if wrong then next check
}
elseif(8>9)
{
echo "this is again wrong";
}
elseif(9>12)
{
echo "this is too wrong";
}
else
echo "this is last";
echo "<br>";
//second example
$price = 20;
if ($price < 10)
{
echo "this is not right ";
}
elseif ($price < 20)
{
echo "this is again not right";
}
elseif ($price < 20)
{
echo "this is too not right";
}
else
echo "this is end";
?>

Switch Statement:-
Switch Statement executes one of many Statement when true.
ex:-

<?php
$value = 20;
switch ($value)
{
case 10:
echo "this is first";
break;
case 20:
echo "this is second";
break;
case 30:
echo "this is third";
break;
default:
echo "this is final";
}
echo "<br>";
$value = 10;
switch ($value)
{
case 11:
echo "Monday <br>";
break;
case 12:
echo "Tuesday <br>";
break;
case 10:
echo "Sunday <br>";
break;
default:
echo "End day <br>";
}
$value = "Saturday";
switch ($value)
{
case "Monday":
echo "Office <br>";
// break;
case "Tuesday":
echo "Office <br>";
// break;
case "Saturday":
echo "Party night <br>";
// break;
default:
echo "Party day <br>";
}
?>

If and nested if:-
If and nested if multiple code executes when true total statement print and when wrong then wrong statement print.
ex:-

<?php
// (if and nested if statement example)
if (30>2): //when true total echo print and when wrong then wrong statement print
echo "this is true <br>";
endif;
echo "this is wrong <br>";
if (50>55):
echo "this is true <br>";
endif;
echo "this is wrong";
echo "<br>";
echo "<br>";
echo "<br>";
// second method type
if(10<12)
{
echo "this is right <br>";
if (22>21)
{
echo "this is right too <br>";
}
// echo "this is wrong too";
if (45<40)
{
echo "this is not right <br>";
}
if(44>30)
{
echo "this is wrong <br>";
}
}
echo "this is end";
?>

If… else… nested…if:-

<?php
//if else
if(12>14){
echo "this is right <br>";
}
else
{
echo "this is too right <br>";
}
echo "this is wrong <br>";
//if else nested if
if(15>14){
echo "this is start <br>";
if(17>18){
echo "this is first <br>";
}
else {
echo "this is first else <br>";
}
}
else{
echo "this is second else <br>";
}
//if else nested if
if(15>16){
echo "this is start <br>";
if(17>18){
echo "this is first <br>";
}
else {
echo "this is first else <br>";
}
}
else{
echo "this is second else <br>";
}
?>

Certification Courses

DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.