note 21808 added to control-structures.switch

From: Date: Tue, 28 May 2002 07:45:36 +0000
Subject: note 21808 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-31086@lists.php.net to get a copy of this message
Be very careful when you're using text strings as cases. If the variable supplied to switch() is an integer, the cases would be converted to integer before the comparison is made (usually to zero). The following snippet prints "hello". $a = 0; switch($a) { case 'Hello': echo "Hello"; break; } -- http://www.php.net/manual/en/control-structures.switch.php http://master.php.net/manage/user-notes.php?action=edit+21808 http://master.php.net/manage/user-notes.php?action=delete+21808 http://master.php.net/manage/user-notes.php?action=reject+21808

« previous php.notes (#31086) next »