How To Use Php Conditional Statement Example
Teams applying “How To Use Php Conditional Statement Example” in a production project can use the official walkthrough to record implementation, review and debugging time, then compare that effort with tests and shipped functionality instead of treating activity as performance by itself.
Before copying the example into a live application, confirm version-specific behaviour with the PHP project and test it against the project’s actual database and runtime.
Hi guys,
Today i will explained how to use php conditional statement in your php file. This example is so easy to use in php. This example to i am use in many conditional statement in php file.
THe conditional statement is provided in a php in default. Conditional statement use to vary easy here.
THis example to i am use in if condition,if..else condition,if...elseif...else conditon and last to use in switch case conditional statement use.So you are follow for my step by step.
So let's start to the example.
If Condition
The if condition is working to execute in only true the condition in php.
<?php
$t = 120;
if ($t == "120") {
echo "Have a good day!<br>";
}
?>
If..else Condition
If..else condition is work to the true or false part. The condition is true then execute the if statement and condition is false then execute in false part.
<?php
$t = 120;
if ($t == "20") {
echo "Have a good day!<br>";
} else {
echo "Have a good night!<br>";
}
?>
if...elseif...else Condition if...elseif...else condition statement executes different codes for more then two conditions
<?php
$t = 120;
if ($t != "120") {
echo "Have a good morning!<br>";
} elseif ($t == "120") {
echo "Have a good day!<br>";
} else {
echo "Have a good night!<br>";
}
?>
Switch..case Conditional
Switch statement is used to perform different actions code on different conditions. The switch statement to select one of many blocks of code to executed.
<?php
$favcolor = "blue";
switch ($favcolor) {
case "red":
echo "Your favorite color is red!<br>";
break;
case "blue":
echo "Your favorite color is blue!<br>";
break;
case "green":
echo "Your favorite color is green!<br>";
break;
default:
echo "Your favorite color is neither red, blue, nor green!<br>";
}
?>
now you can check your own.
- How to Check if String Contains Regex in PHP?
- PHP Array_column() Function Example
- PHP Generate List of Random Numbers Between 0 and 100 Example
- How to User Login with Facebook in PHP?
- How to Explode Every Character into Array Using PHP Example?
- PHP Form Validation Tutorial
- PHP Convert XML to JSON Example
- How To Add Year To Current Date In Php?