note 28778 added to control-structures.switch

From: Date: Thu, 23 Jan 2003 17:21:30 +0000
Subject: note 28778 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-42653@lists.php.net to get a copy of this message
In answer to njones at fredesign dot com, what you're seeing is the way the switch statement is supposed to work. The switch statement evaluates the cases, top to bottom, until it finds the first one that matches the value being switch()ed on. So, for example, if you had: switch(2) { case 1: echo "One\n"; break; case 2: echo "Two\n"; break; case 3: echo "Three\n"; break; case 2: echo "Two again\n"; break; } Only "Two" would get echoed. "Two again" would NOT get echoed, because once the first case matches, the rest of them do NOT get evaluated. As soon as a matching case is found, the statements starting at that case get executed until the first break, then control flows out the bottom of the switch block. -- http://www.php.net/manual/en/control-structures.switch.php http://master.php.net/manage/user-notes.php?action=edit+28778 http://master.php.net/manage/user-notes.php?action=delete+28778 http://master.php.net/manage/user-notes.php?action=reject+28778

« previous php.notes (#42653) next »