diff --git a/language/control-structures.xml b/language/control-structures.xml index 5a40f805d0..561681bff8 100644 --- a/language/control-structures.xml +++ b/language/control-structures.xml @@ -1,5 +1,5 @@ - + Control Structures @@ -126,7 +126,7 @@ if ($a > $b) { - <literal>elseif</literal> + <literal>elseif</literal>/<literal>else if</literal> elseif, as its name suggests, is a combination of if and else. Like @@ -175,6 +175,44 @@ if ($a > $b) { elseif expression evaluated to &true;. + + + Note that elseif and else if + will only be considered exactly the same when using curly brackets + as in the above example. When using a colon to define your + if/elseif conditions, you must + separate else if into two words, or PHP will + fail with a parse error. + + + + + + $b): + echo $a." is greater than ".$b; +else if($a == $b): // Will not compile. + echo "The above line causes a parse error."; +endif; + + +/* Correct Method: */ +if($a > $b): + echo $a." is greater than ".$b; +elseif($a == $b): // Note the combination of the words. + echo $a." equals ".$b; +else: + echo $a." is neither greater than or equal to ".$b; +endif; + +?> +]]> + + +