The if statement


The if statement

 if (expr)     statement 

The if statement is one of the most important statements in PHP because it allows for conditional execution of code fragments. Here, expr is evaluated, and if it evaluates to TRUE, PHP will execute statement, whereas if expr evaluates to FALSE, PHP will ignore statement.

Sometimes you will want to execute more than a single statement conditionally. In that case, you can group several statements into a compound statement. For example, this code displays a message if $value1 is bigger than $value2 and, if so, swaps the values:

 <?php if ($value1 > $value2) {     echo "$value1 is bigger than $value2\n";     echo "Swapping the values.";     $temp = $value1;     $value1 = $value2;     $value2 = $value1; } ?> 



    Spring Into PHP 5
    Spring Into PHP 5
    ISBN: 0131498622
    EAN: 2147483647
    Year: 2006
    Pages: 254

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net