note 48410 added to control-structures.switch

From: Date: Wed, 22 Dec 2004 19:43:38 +0000
Subject: note 48410 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-82183@lists.php.net to get a copy of this message
A word of caution around the order used for the case/default controls. I notice that a lot of people do not break; the default section and the following could lead to incorrect results when run. $a = "lowercase"; switch ( $a ) { default: $a = strtoupper( $a ); print $a . "<br />"; case ( 'LOWERCASE' ): print $a . "<br />"; break; } Result: LOWERCASE LOWERCASE Placing a break; in the default control will result in: LOWERCASE .. as expected. Also, placing the default section at the bottom (as in an else control) will also display the correct result. ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+48410 Delete -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes&reason=bad+code Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes&reason=spam Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes&reason=useless+example Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes&reason=contains+commercial+links Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+48410&report=yes&reason=useless+note Reject -- http://master.php.net/manage/user-notes.php?action=reject+48410&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#82183) next »