20 – PHP If Statement


This tutorial is all about PHP If Statement.
The if statement is a powerful tool when used properly and it is also necessary for most programming languages because it serves as a conditional operator of your statement. The if statement has different syntax in other programming languages while there are some languages that has the same syntax just like C#, PHP, C++, Java, etc..


In PHP the syntax of if statement are the following:


For those who are not familiar with the if statement, come to think of this folowing statement:


In our daily life we always make decisions for isntance, If you have a long quiz tomorrow in your Math subject, then you will study hard and review those lessons that your teacher discussed. Otherwise, you will fail the long quiz.


The given example was just a simple if/then statement that happens in our daily life and this quite often appears in programming.




if statement Code:


Your name is Kenjie!
Hello Kenjie

You will notice that we compare the variable $your_name with kenjie because of that, the result will be true or equal.


Now, let see what will happen when the if statement is not equal or false.

if statement Code:


In the given example, the variable $your_name contained the value “Craig” which is obviously not equal to “Kenjie“. Therefore: The result is false or not equal.



Readers might read also:




Looking for more source code? Type your keyword here here!


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.