note 125150 added to control-structures.switch
| From: | brentmmonson at gmail dot com | Date: | Sat, 27 Jun 2020 22:53:39 +0000 |
| Subject: | note 125150 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-214812@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 45.112.84.4
Probable Submitter: 103.51.166.36 (proxied: 107.184.130.94)
----
Manual Page -- http://php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/125150
Del: integrated -- https://master.php.net/note/delete/125150/integrated
Del: useless -- https://master.php.net/note/delete/125150/useless
Del: bad code -- https://master.php.net/note/delete/125150/bad+code
Del: spam -- https://master.php.net/note/delete/125150/spam
Del: non-english -- https://master.php.net/note/delete/125150/non-english
Del: in docs -- https://master.php.net/note/delete/125150/in+docs
Del: other reasons-- https://master.php.net/note/delete/125150
Reject -- https://master.php.net/note/reject/125150
Search -- https://master.php.net/manage/user-notes.php