PHP If else

In PHP If else is a control structure and it is the heart topic of PHP Scripts. It will be used whenever you have performed the conditional statements.


PHP if statement executes the block of code when the expression evaluates to TRUE



Inside HTML / Javascript or CSS, we can write if statement like below:

We can write if statements within another if statements infinitely.



Whenever the expression in if statement evaluates to FALSE and it constructed with else statement and then the “else” block will be executed.



Like if statement, else statement also can be nested infinitely.

else if

We can understand with the name itself. If we combine both else and if statements together, it is called as “elseif” or “else if” statement.
There should be else block after elseif block, if else part is missing after elseif block then PHP throws fatal error.


Consider the following example, there we have used all the if, else and else if concepts together.


We will discuss later about the rand() function.

Click the below button to see the demo.

Please follow and like us:

Leave a Reply

Your email address will not be published. Required fields are marked *