How to use PHP Case | PHP switch select case with syntax and examples

Introduction:

Switch / case is a type of decision making in php. Use Switch / case statement option when you have many options and have to execute one of those. This is helpful where you have to use long blocks of if..elseif..else code.

Syntax:


Example:


Switch Statement – Default case

In the above example there is no chance that all of the  none of the case will be true. However in many cases there will be situations where where all conditions/cases are false. In case of If statement we used else statement. In Switch statement we use Default case.

Example:


You can check by changing variable name value from NY to IL, Al and then to some other to check output.

Was this article helpful?

Related Articles

Leave A Comment?