Output PHP switch ()

Is this a good practice ... i.e. grouping a default case with another?

switch ($cond){ case 1: ...; break; case 2: ...; break; case 3: default: ...; break; } 
+6
source share
2 answers

It makes sense to do it this way.

In addition, @Ian is correct, but in a limited area. If you want additional features to be applied to case 3 , you will leave it as it is. Until you break , it will move on to the next case .

+3
source

This makes case 3 unnecessary, so I would delete it and leave it as default

+1
source

Source: https://habr.com/ru/post/897163/


All Articles