Go Back   Webmaster Forum > Development > Programming > PHP
REMOVE the ads below !
Reply
 
LinkBack Thread Tools
  # 1 (permalink)
Old
Junior Geek
Posts: 142
Join Date: Feb 2007
iTrader: (0)
Post PHP 02 : To be or not to be - 09-27-2007

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=$i=$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"


Thanks,
Aqua


-------------------
http://www.aquafolie.org

Last edited by aquafolie : 09-27-2007 at 04:43 PM.
Reply With Quote
Reply


Thread Tools



PSD to HTML

vBulletin®, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd. | SEO by vBSEO | Skin developed by vBStyles.com