if/elseif/else
if ( $x == 5 ) {
// do something
} elseif ( $x == 9 ) {
// do something else
} elseif ( $x > 0 ) {
// do a third thing
} else {
// if all else fails, do this
}
if ( isset($y) ) {
// Checks to see if the variable $y has a value
}
switch
switch ($x) {
case 5:
// do something
break ;
case 9:
// do something else
break ;
default:
// do your "otherwise" stuff here
}
Looping Structures
// for loop for ( $i = 0; $i <= $max; $i++ ) { // statements to repeat } // while loop // if $value starts out <= $max, the statements will NEVER run while ( $value <= $max ) { // statements to repeat // Be sure to change $value in here! } // while loop // will run at least once do { // statements to repeat } while ( $value <= $max ) ; // foreach loop for ( $presidents as $num => $name ) { // statements to repeat // We'll look at this in the section on Array variables }
Copyright © 2003
Henry H. Hartley
All Rights Reserved