note 115425 added to control-structures.switch
| From: | druellan at sfidastudios dot com | Date: | Mon, 21 Jul 2014 21:27:37 +0000 |
| Subject: | note 115425 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200004@lists.php.net to get a copy of this message | ||
Be careful if you have mixed types of values in the switch statement. Explicitly cast your variables
where possible to avoid mismatch:
<?php
$var = 0;
// This match case #1
// switch ( $var )
// This works as expected
switch ( (string)$var )
{
case "0string":
echo "0string match";
break;
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 181.166.39.28
----
Manual Page -- http://php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/115425
Del: integrated -- https://master.php.net/note/delete/115425/integrated
Del: useless -- https://master.php.net/note/delete/115425/useless
Del: bad code -- https://master.php.net/note/delete/115425/bad+code
Del: spam -- https://master.php.net/note/delete/115425/spam
Del: non-english -- https://master.php.net/note/delete/115425/non-english
Del: in docs -- https://master.php.net/note/delete/115425/in+docs
Del: other reasons-- https://master.php.net/note/delete/115425
Reject -- https://master.php.net/note/reject/115425
Search -- https://master.php.net/manage/user-notes.php