This tutorial contains terms that even the begginer php coder should know. I will not be explaining every single term. If there are any questions simply post them, and they will be answered.
An if else statement is used to basicly check to see if something is true or false. An if else statement could be used to ask 'if $variable is true then do this, otherwise the variable is false so do something else. You could of course ask 'if variable is false do this, otherwise do something else...
--------------------------
Now I will be showing, and explaining an example of the if else code.
Let's say you have five dollars and you want to know what you could afford.
First let's go over the different symbols used in an if else statement.
== Is equal to (two equal signs)
!= (or) <> Is not equal to
> Is greater than
< Is less than
>= Is greater than or equal to
<= Is less than or equal to
I will be using two variables to demonstrate what can, and cannot be afforded.
I will use the '$fivedollars' variable to set the ammount of money you have, and I will use the '$item' variable to deomonstrate the price of the item you want to buy.
PHP Code:
<?php
$fivedollars = 5;
$item = 5.01;
if ($item < $fivedollars) {
echo "You can afford this.";
} else {
echo "You cannot afford this.";
} ;
?>
The code is very simple.
These two are your variables:
$fivedollars = 5;
$item = 5.01;
This asks if the item is less than five dollars, and if so to output the message "You can afford this."
if ($item < $fivedollars) {
echo "You can afford this.";
}
This asks if the item is more than five dollars, and if so to output the message "You cannot affor this."
I understand this is very simple, and probably not as well organized, and thought out as possible.. I'm just trying to emphasize the importance on simple functions such as the if else statement.