language/control-structures/elseif.xml
bbaf4fea6946bf6d0b67573d5f2f96c5a2c5d678
...
...
@@ -2,7 +2,7 @@
2
2
<!-- $Revision$ -->
3
3

4
4
<sect1 xml:id="control-structures.elseif" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
-
<title><literal>elseif</literal>/<literal>else if</literal></title>
5
+
<title>elseif/else if</title>
6
6
<?phpdoc print-version-for="elseif"?>
7
7
<para>
8
8
<literal>elseif</literal>, as its name suggests, is a combination
...
...
@@ -37,12 +37,11 @@ if ($a > $b) {
37
37
There may be several <literal>elseif</literal>s within the same
38
38
<literal>if</literal> statement. The first
39
39
<literal>elseif</literal> expression (if any) that evaluates to
40
-
&true; would be executed. In PHP, you can also
41
-
write 'else if' (in two words) and the behavior would be identical
42
-
to the one of 'elseif' (in a single word). The syntactic meaning
43
-
is slightly different (if you're familiar with C, this is the same
44
-
behavior) but the bottom line is that both would result in exactly
45
-
the same behavior.
40
+
&true; would be executed. In PHP, it's possible to write
41
+
<literal>else if</literal> (in two words) and the behavior would be identical
42
+
to the one of <literal>elseif</literal> (in a single word). The syntactic meaning
43
+
is slightly different (the same behavior as C) but the bottom line
44
+
is that both would result in exactly the same behavior.
46
45
</simpara>
47
46
<simpara>
48
47
The <literal>elseif</literal> statement is only executed if the
...
...
@@ -56,10 +55,11 @@ if ($a > $b) {
56
55
<simpara>
57
56
Note that <literal>elseif</literal> and <literal>else if</literal>
58
57
will only be considered exactly the same when using curly brackets
59
-
as in the above example. When using a colon to define your
60
-
<literal>if</literal>/<literal>elseif</literal> conditions, you must
61
-
not separate <literal>else if</literal> into two words, or PHP will
62
-
fail with a parse error.
58
+
as in the above example. When using a colon to define
59
+
<literal>if</literal>/<literal>elseif</literal> conditions, the use
60
+
of <literal>elseif</literal> in a single word becomes necessary. PHP
61
+
will fail with a parse error if <literal>else if</literal>
62
+
is split into two words.
63
63
</simpara>
64
64
</note>
65
65
<para>
...
...
@@ -69,17 +69,17 @@ if ($a > $b) {
69
69
<?php
70
70

71
71
/* Incorrect Method: */
72
-
if($a > $b):
72
+
if ($a > $b):
73
73
echo $a." is greater than ".$b;
74
-
else if($a == $b): // Will not compile.
74
+
else if ($a == $b): // Will not compile.
75
75
echo "The above line causes a parse error.";
76
76
endif;
77
77

78
78

79
79
/* Correct Method: */
80
-
if($a > $b):
80
+
if ($a > $b):
81
81
echo $a." is greater than ".$b;
82
-
elseif($a == $b): // Note the combination of the words.
82
+
elseif ($a == $b): // Note the combination of the words.
83
83
echo $a." equals ".$b;
84
84
else:
85
85
echo $a." is neither greater than or equal to ".$b;
86
86