switch ($para1) { case 1: return self::otherFunction($para2); break; }
example, if Case 1 is met, then does the last break still need to be?
Reply content:
switch ($para1) { case 1: return self::otherFunction($para2); break; }
example, if Case 1 is met, then does the last break still need to be?
No, break is unnecessary if you use return as the end of the case.
There's definitely no need for the following break to return.
According to the landlord's writing, break will not need, because the program in return when the jump, the code behind will not be executed, so break has no relationship.
From the code of the caption, break is not required because the return code is no longer executed.
Plus break is never wrong, and sometimes it goes wrong without a break. It is recommended to add break to any situation so that other small partners working together can better understand the code.
If you have only one option, of course not, if there are other case options, it is required, otherwise the program will execute sequentially to the following option until a break or end is encountered, and sometimes this feature will be applied to handle the same handling of multiple options. That is, in multiple cases no write processing and break, only the last case to add the processing mode.
Comments do not post code, I modify: The following example:
switch( $i ){ case 1: case 2: case 3: $c =555; break; default: $c =2;}
You can try this example ~
PHP is the best language in the world