Well we're happy to display some informations on the document but we want more !
Now I use the document "test.php" and post after post i will use more code and less text.
Now we will see the "condition". This strange word means that we will see the 'if,while,for'.
The structure of "if" is : PHP Code:
<?php
if (condition){result;}
elseif(other condition){other result;}
else{other result;}
?>
"If" doesn't use ";" because it isn't a function, but it can contains functions :
PHP Code:
<?php
if($what=='yes'){echo 'okay yes';} //as you can see we have 2 equal !
elseif($what=='no'){echo 'not okay no';}
else{echo 'no result';} // here no condition is needed (of course)
?>
Don't miss () and {}, it is 2 different things
The structure of "while" is : PHP Code:
<?php while(condition){result;} ?>
Like "if", the condition use a double equal and means "while the condition is true, display a result"
example :
PHP Code:
<?php while($what=='yes'){echo 'okay yes';}?>
the structure of "for" is : PHP Code:
<?php for(condition){result;) ?>
this is quite different from "while" :
PHP Code:
<?php for($i=0 ; $i=5 ; $i++) /* A variable $i is declared equal to 0,
the maximum of $i is 5 and we want to add +1 when the "for" ending*/
{echo $i;}
?>
This will display "012345"
For "while" and "if" it isn't needed to use "==", you could use also "<" or ">" or "<=" or ">="
Example complete :
PHP Code:
<?php $k=0;
while($k<5)
{echo $k.'<br>';
$k++;}?>
First we declare $k equal to 0 and we say, while $k is under 5 (strictly) then display $k, return to the line and add +1 to $k and then restart the same condition. This will display :
"0
1
2
3
4"
and not 5 because it is strictly under 5 and it looks like "for"
