#45 Working with If and Switch Statements

PhpStorm gives you the power to convert an if block to a switch statement and vise versa.

Simply place the cursor on the if block and press Alt+Enter to invoke the intention actions menu, then select Replace ‘if’ with ‘switch’ from the list. You can even apply the action to a switch statement to convert it to an if block.

Note that the intention action is only available if every statement in the if block is using an equality condition.

Further Reading

comments powered by Disqus