note 115851 added to control-structures.elseif
| From: | qualitycoder | Date: | Fri, 03 Oct 2014 14:39:23 +0000 |
| Subject: | note 115851 added to control-structures.elseif | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200578@lists.php.net to get a copy of this message | ||
The reason 'else if' (with a space) works with traditional syntax and not colon syntax is
because of a technicality.
<?php
if($var == 'Whatever') {
} else if($var == 'Something Else') {
}
?>
In this instance, the 'else if' is a shorthand/inline else statement (no curly braces)
with the if statement as a body. It is the same things as:
<?php
if($var == 'Whatever') {
} else {
if($var == 'Something Else') {
}
}
?>
If you were to write this with colon syntax, it would be:
<?php
if($var == 'Whatever'):
else:
if($var == 'Something Else'):
endif;
endif;
?>
----
Server IP: 72.52.91.14
Probable Submitter: 72.48.140.132
----
Manual Page -- http://php.net/manual/en/control-structures.elseif.php
Edit -- https://master.php.net/note/edit/115851
Del: integrated -- https://master.php.net/note/delete/115851/integrated
Del: useless -- https://master.php.net/note/delete/115851/useless
Del: bad code -- https://master.php.net/note/delete/115851/bad+code
Del: spam -- https://master.php.net/note/delete/115851/spam
Del: non-english -- https://master.php.net/note/delete/115851/non-english
Del: in docs -- https://master.php.net/note/delete/115851/in+docs
Del: other reasons-- https://master.php.net/note/delete/115851
Reject -- https://master.php.net/note/reject/115851
Search -- https://master.php.net/manage/user-notes.php