The else Statement


The else Statement

 if (expr)     statement else     other_statement 

Sometimes you will want to execute a statement if a certain condition is true, but a different statement otherwise. That's what else does; it extends an if statement to execute a different statement in case the condition in the if expression evaluates to FALSE.

For example, this code indicates which is bigger, $value1 or $value2:

 <?php     if ($value1 > $value2) {         echo "$value1 is larger than $value2";     } else {         echo "$value1 is not larger than $value2";     } ?> 

The else statement is only executed if the if condition evaluates to FALSE.



    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