PHP if else statement
In this tutorial I will show you how to use a bit more complex control structure if - elseif - else in PHP.
Tutorial info:
Name: | PHP if else statement |
Total steps: | 2 |
Category: | Basics |
Level: | Beginner |
Bookmark PHP if else statement

Step 1 - The if - else statement
PHP if else statement
In the previous tutorial you have learnd how to use the if statement in PHP. However that post only shows the very basic syntax of this powerfull control structure. Now you will learn how to use more complex branching.
In the previous tutorial we used the following code:
Let's see how to use it:
Code:
if ($userName == 'Peter') {
echo 'Hello Peter!';
echo 'Nice to see you again!';
} else {
echo 'Hey, you are not Peter!';
echo 'Who are you?';
}
Of course we can extend it a bit more.
Next Step of PHP if else statement
Tags: php if else, if else, php, if, else
PHP if else statement - Table of contents |
---|
Step 1 - The if - else statement |
Step 2 - The if-elseif-else statement |