note 97112 added to control-structures.switch
| From: | hackajaryahoocom at osu1 dot php dot net | Date: | Thu, 01 Apr 2010 23:21:35 +0000 |
| Subject: | note 97112 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-167635@lists.php.net to get a copy of this message | ||
Apparently you need to be extra careful with "0" (zero) in your case statements when
mixing int and string values:
switch($key) {
case 0: echo "only if I am zero";break;
case 1: echo "I'm one";break;
case "E1": echo "Why don't you output me?";break;
default: echo "No value Found";
}
Switch will be convinced that you mean "0" when you really mean "E1" unless you
wrap it in quotes:
switch($key) {
case '0': echo "only if I am zero";break;
case 1: echo "I'm one";break;
case "E1":echo "Yay! I'm back!";break;
default: echo "No value Found";
}
Maybe this is what they mean by "loose comparison" with True, False operators?
----
Server IP: 208.69.120.55
Probable Submitter: 63.82.71.139
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/97112
Del: integrated -- https://master.php.net/note/delete/97112/integrated
Del: useless -- https://master.php.net/note/delete/97112/useless
Del: bad code -- https://master.php.net/note/delete/97112/bad+code
Del: spam -- https://master.php.net/note/delete/97112/spam
Del: non-english -- https://master.php.net/note/delete/97112/non-english
Del: in docs -- https://master.php.net/note/delete/97112/in+docs
Del: other reasons-- https://master.php.net/note/delete/97112
Reject -- https://master.php.net/note/reject/97112
Search -- https://master.php.net/manage/user-notes.php