note 84150 added to control-structures.switch
| From: | mmxg at shaw dot ca | Date: | Tue, 01 Jul 2008 08:30:11 +0000 |
| Subject: | note 84150 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-141026@lists.php.net to get a copy of this message | ||
In reply to lko at netuse dot de
Just so others know whom may not, that's because PHP does automatic type conversion if a string
is evaluated as an integer (it sees the 2 in '2string' so when compared like if
('2string' == 2), PHP sees if (2 == 2) ).
I just tested it, but if you go:
<?php
$string="2string";
switch($string)
{
case (string) 1:
echo "this is 1";
break;
case (string) 2:
echo "this is 2";
break;
case '2string':
echo "this is a string";
break;
}
?>
The output will be "this is a string" and if you change $string to "2" it will
again be "this is 2".
Just in case that may help anyone who may run into that problem.
----
Server IP: 216.235.15.211
Probable Submitter: 24.108.81.100
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/84150
Del: integrated -- https://master.php.net/note/delete/84150/integrated
Del: useless -- https://master.php.net/note/delete/84150/useless
Del: bad code -- https://master.php.net/note/delete/84150/bad+code
Del: spam -- https://master.php.net/note/delete/84150/spam
Del: non-english -- https://master.php.net/note/delete/84150/non-english
Del: in docs -- https://master.php.net/note/delete/84150/in+docs
Del: other reasons-- https://master.php.net/note/delete/84150
Reject -- https://master.php.net/note/reject/84150
Search -- https://master.php.net/manage/user-notes.php