note 125150 deleted from control-structures.switch by crell

From: Date: Mon, 27 Jun 2022 20:36:13 +0000
Subject: note 125150 deleted from control-structures.switch by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218627@lists.php.net to get a copy of this message
Note Submitter: brentmmonson at gmail dot com ---- You can use multiple break statements within a case. In this contrived example, I get out of the first case of the switch statement once a condition is met. Just remember to include another break statement as a failsafe. <?php $disk = '3.5 inch floppy'; switch ($disk) { case '5 inch floppy': case '3.5 inch floppy': case 'usb': case 'cd': echo "Reading disk..."; if (strpos($disk, 'floppy') !== false) { echo "It bent."; break; } echo "It worked."; break; // failsafe default: echo "Don't stick cupcakes in here."; break; }

« previous php.notes (#218627) next »