PHP Switch Statement | Tutorial

Опубликовано: 29 Сентябрь 2024
на канале: YouAccel
3
0

Course Title: Web Development Masterclass
Course Link: http://youaccel.com/admin/cdisplay.ph...

Facebook:   / youaccel  
Twitter:   / youaccel  
Website: http://youaccel.com

Tutorial Content:

The switch statement compares the value of an expression against a set of predefined conditions, also referred to as cases.

If there is a match, the block of code associated with that case is executed.

In this example, we have a variable with the value Volvo assigned to it.

Next we've created a switch statement pertaining to the car variable, with four cases.

In the case that the car variable is equal to Volvo, we will output the text "You drive a Volvo".
In the second case, if the car variables value is BMW, we will output the text "You drive a BMW".
In the third case, if the car variables value is Honda, we will output the text you drive a Honda.
We then use the default statement to output the text, "You don't drive" if the car variable does not equal any of the cases defined above.