We'll start of with if
Here is the basic usage of it
| <?php
if (variable CONDITION value) { //the condition was met } ?> |
variable would be something like $variable
CONDITION can be something like == (equal to) or <= (less than or equal to)
value can be 10 or 20, doesn't matter
So we'll do this
| <?php
if ($variable == 10) { //$variable does equal 10 } ?> |
Now we'll add an ELSE statement to the mix
| <?php
if ($variable == 10) { //$variable does equal 10 } else { //$variable does NOT equal 10 } ?> |
Pretty straight forward, let's try an ELSEIF statement
| <?php
if ($variable == 10) { //$variable does equal 10 } elseif ($variable == 20) { //$variable does NOT equal 10, but it DOES equal 20 } ?> |
A bit confusing at first, but I'm sure you'll get the jist of it
Aside from if statements, there are switch statements
| <?php
switch ($variable) { case 'one': //$variable equals one break; case 'two': //$variable equals two break; default: //$variable does NOT equal one or two break; } ?> |
So if $variable equals one, then it would trigger the first bit, if it didn't equal one or two, it would trigger DEFAULT, which is like the ELSE statement for IF's
That's it for the tutorial, after you get comfortable with procedural programming, be sure to checkout object orientated programming tutorials!


