note 62159 added to control-structures.switch
| From: | nate at osu1 dot php dot net | Date: | Tue, 21 Feb 2006 16:49:55 +0000 |
| Subject: | note 62159 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104140@lists.php.net to get a copy of this message | ||
if you need to operate on the switch variable in the case statements you can access it as
$_.
For example, I was using switch to iterate over a set of mime types and I wanted to catch the
image\* types.
To do that I wrote this clause:
switch($mime){
case(preg_match('/image.*/', $_)):
...put code here...
break;
}
This tip may seem obvious to the experienced user, but not so obvious to the beginner.
----
Server IP: 216.194.113.175
Probable Submitter: 129.174.27.154
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+62159
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62159&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+62159&report=yes
Search -- http://master.php.net/manage/user-notes.php