Anthony Stansbridge
Anthony Stansbridge

Reputation: 55

PHP switch() skipping breaks to apply extra logic

I have a flag that when passed to a switch statement needs different logic applied to it, three of the cases apply the same logic apart from one of those cases (out of the three) has an extra step.

Is this syntactically correct?

switch($foo)
{
 case 1:
      //do something
      break;
 case 2:
      //do step 1 
 case 3:
 case 4:
      //do step 2
      break;
}

Upvotes: 1

Views: 104

Answers (1)

Waynn Lue
Waynn Lue

Reputation: 11385

Yes, your code is syntactically correct and will do what you've said in the comments.

Upvotes: 1

Related Questions