In this lesson we will talk about php if else and what does it mean and what we can do with it
so if statement are using to verify a particular condition after it, for example
if you are not busy bring me a cup of coffee, the condition in this case is not busy, if it is true than he will bring you a cup of coffee,if not he will beat you hhhhhh just kidding he will not bring you the coffee cup,
So let's write some code
<?php
$p = "busy" ;
if ($p == "busy") {
echo "sorry i can't i'm busy" ;
}
?>
In this example we define a variable and we gave him the value of busy, and put a conditional statement after it to check if the variable p is equal to busy then he will print sorry i can't i'm busy
So write this code and you will see in the screen this statment sorry i can't i'm busy
Let's do other example with if and else
<?php
$p = "not busy" ;
if ($p == "busy") {
echo "sorry i can't i'm busy" ;
}
else {
echo "ok no probleme" ;
}
?>
In this example the program will check if the variable p equal to busy, but as we see it's not so he will scroll down to the else statement and do what is between brackets
I hope you understand this lesson, php if else
any question just leave a comment
See you next time.
php switch
No comments :
Post a Comment