PHP If Statements
So you know a little bit of PHP and your curious as to what else you can do with it, well you can do If statements with PHP know if you don't know what that means let me explain a little bit. An If statement lets you code have a brain, it can now officialy think for itself. An If statement can be explained just like this, imagine you want to choose between two things you have salad and ice cream now follow my example If statement below and it should explain itself.
if ( i eat salad ) <---- the item in parantheses is called the condition
i lose weight
else ( i eat ice cream)
i gain weight
The example "code" above explains what If statements do it lets your program choose what it wants to do as it is running. In PHP there are four types of If Statements and they are explained out in more detail below:
if statement - use this statement to execute some code only if a specified condition is true
if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
if...elseif....else statement - use this statement to select one of several blocks of code to be executed
So the basic way to use the If Statement is:
if(some condition is true)
then do this thing
The way to use the If Else Statement is:
If(this code is true)
do this code right here
Else
do this stuff down here
To use If..ElseIf..Else do some code like this below:
if (this is condition is true)
code to be executed if condition is true
elseif (if this condition is true)
code to be executed if condition is true
else
code to be executed if condition is false
if ( i eat salad ) <---- the item in parantheses is called the condition
i lose weight
else ( i eat ice cream)
i gain weight
The example "code" above explains what If statements do it lets your program choose what it wants to do as it is running. In PHP there are four types of If Statements and they are explained out in more detail below:
if statement - use this statement to execute some code only if a specified condition is true
if...else statement - use this statement to execute some code if a condition is true and another code if the condition is false
if...elseif....else statement - use this statement to select one of several blocks of code to be executed
So the basic way to use the If Statement is:
if(some condition is true)
then do this thing
The way to use the If Else Statement is:
If(this code is true)
do this code right here
Else
do this stuff down here
To use If..ElseIf..Else do some code like this below:
if (this is condition is true)
code to be executed if condition is true
elseif (if this condition is true)
code to be executed if condition is true
else
code to be executed if condition is false