Monday, July 19, 2010

PHP tutorial Part5

Posted by Syarif | Monday, July 19, 2010 | Category: |

CONDITIONAL STATEMENT

IF
The syntax to write “IF” function in PHP is

<? If (condition){ statement;} ?>


The code above, when the condition is right, so the system will execute the statement. If not, the system will neglect the statement inside the {}.
If you want to make another statement if the condition is FALSE, you can use “ELSE” after “IF”.
For example:

<? If (condition) {Statement_a}
Else {statement_b;} ?>



*important note: if you put ELSE function, don’t put the (;) on the end of IF statement (true statement). PHP read the IF ELSE function as one pair of code.
If you have more than two conditions, maybe three, you should use ELSEIF function.
For example:

<?
If (condition ){statement_a}
Elseif {statement_b}
Else {statement_c;}
?>


SWITCH
Switch usually used when the condition is more than three conditions.
For example:

<?
Switch (variable)
Case case1;
Statement_a;
Case case2;
Statement_b;
Case case3;
Statement_c;
Case case4;
Statement_d;
Break;
?>

Currently have 0 comments:


Leave a Reply