Back-End Development PHP basics

PHP switch Statement

The PHP switch statement is used to perform different actions based on different conditions.

Syntax

Let us see how it works

We have a variable or expression ‘x’. This expression ‘x’ is checked with value of each case. If there is a match, the block is executed.break is used to prevent code running to next case. When there is no match defaultblock is executed.

Example:

Result:
Third day of the week