PHP Statements

if The if statement asks whether something is true. If the test is true then the statement after the if statement is used; otherwise it is ignored.
if ($count < 0) $count = 0;
if ($answer != 0) echo $answer;
if ($parameter) {
    // do one thing
} else {
    // do another thing
}
A test is true if it is non-zero, and false if it is zero. An empty string ("") or array is equivalent to zero.
for The for statement is used to do something more than once. A for statement contains three parts: a starting variable, a test, and a change to the variable. The body of the for statement (enclosed by { and }) is run repeatedly until the the test is no longer true.
for ($i=0; $i<10; $i=$i+1) { echo $i; }      // print 0 through 9
$a = array(1,2,3);                          // array with three elements
for ($i=0; $i<count($a); $i++) { echo $a[$i]; }  // print three elements
{} If you want to group more than one statement for use by if or for you can put the curly braces { and } around the statements.
if ($answer == 1) {
    echo "correct answer";
    echo "press return to continue";
}

Home