|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-01-12 18:21 UTC] matthew dot somerville at trinity dot oxford dot ac dot uk
<? $k = "+";
switch($k) {
case "-": print "Oh no!";
case "+": print "Correct!";
}
?>
outputs "Oh no!". I guess this is because as switch uses
==, + and - are both being automatically converted to the
number 0 which then matches? Could switch() perhaps use
=== instead of == in its comparison?
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Nov 05 04:00:01 2025 UTC |
Jesus man. case statements not followed by a break; statement fall through. Your code should read: <? $k = "+"; switch($k) { case "-": print "Oh no!"; break; case "+": print "Correct!"; break; } ?>