note 51252 added to control-structures.switch

From: Date: Thu, 24 Mar 2005 17:01:25 +0000
Subject: note 51252 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-86894@lists.php.net to get a copy of this message
This caught me out. The number '6' when compared with the string '6b' returns true. The solution is to either typecast the compare - ie, " switch ((string)$type): " or to make sure $type is a string (eg $type="6") <? $type=6; switch ($type): case "6b": print "6b: "; print $type; break; case "6": print "6: "; print $type; break; endswitch; ?> ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+51252 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+51252&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+51252&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+51252&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+51252&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+51252&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+51252&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#86894) next »