note 123914 deleted from control-structures.switch by crell

From: Date: Mon, 27 Jun 2022 20:38:45 +0000
Subject: note 123914 deleted from control-structures.switch by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218635@lists.php.net to get a copy of this message
Note Submitter: Manucyan ---- Some tests: switch ('aaaaa') { default : echo "DEFAULT TOP 1"; break; default : echo "DEFAULT TOP 2"; break; case 'aaaaa': echo "CASE TOP 1"; break; case 'aaaaa': echo "CASE TOP 2"; break; default : echo "DEFAULT BOTTOM 1"; break; default : echo "DEFAULT BOTTOM 2"; break; case 'aaaaa': echo "CASE BOTTOM 1"; break; case 'aaaaa': echo "CASE BOTTOM 2"; break; } //return ------> CASE TOP 1 switch ('SOMETHING_THAT_DOESN_T_EXIST') { default : echo "DEFAULT TOP 1"; break; default : echo "DEFAULT TOP 2"; break; case 'aaaaa': echo "CASE TOP 1"; break; case 'aaaaa': echo "CASE TOP 2"; break; default : echo "DEFAULT BOTTOM 1"; break; default : echo "DEFAULT BOTTOM 2"; break; case 'aaaaa': echo "CASE BOTTOM 1"; break; case 'aaaaa': echo "CASE BOTTOM 2"; break; } //return ------> DEFAULT BOTTOM 2 Some observations: - no errors if several identical boxes or defaultes - the last defect takes over - the first of the boxes takes the hand - we can put the default at the top (indeed sometimes it's more intuitive)

« previous php.notes (#218635) next »