Ok let's start with the advanced stuff.
First of all we will talk about the if().
It is really important in PHP and you will often use it. Ok example:
<?php
$var1 = '1';
if ($var1 == '1') {
echo "true";
}
?>
So you see, the if() will check if $var1 contains '1'. If this is true it will print "true" and if it's not true it will do nothing.
You should understand the script completely now.
<?php
$var1 = '0';
if ($var1 == '1') {
echo "true";
} else {
echo "false";
}
?>
Take a look. This script is almost the same like the one above, but now it will do something when $var1 doesn't contain '1'. Ok you know now the basic if(). Let's go on...
<?php
$var1 = '2';
if ($var1 == '1') {
echo "it is 1";
} elseif ($var1 == '2') {
echo "it is 2";
}
?>
The 'elseif ()' is just a "upgraded else ;)
elseif() will check again if the following is true. So you can do almost the same with elseif then you can do with switch:
<?php
$var1 = '2';
switch ($var1) {
case 1:
echo "case 1 is true";
break;
case 2:
echo "case 2 is true";
break;
}
?>
Just read that script carefuly and you will know what it will do.
case 1 for example is doing the same like: if ($var1 == '1') { ... }
I hope you understand now.
Ok next one the while().
while() is doing something until the stuff in (..) is getting false. An example:
<?php
$var1 = '0';
while ($var1 <= '4') {
echo $var1;
$var1++;
}
?>
This script will count to 4.
To understand the script, you must know that $var1++; will do $var1 + 1, so from '0' to '1' and so on. When the $var1 contains '5' the while() will stop because it is not less or equal to '4'.
The rest of this tutorial will follow soon....