php tutorial - PHP Switch Statement - php programming - learn php - php code - php script
- Switch statement is used to select one of the many blocks code to be executed.
- You can use the “switch” statement to alter the flow of a program.
- Conditional statements are used to perform actions on different conditions.
Learn PHP - PHP tutorial - Switch Statement - PHP examples - PHP programs
php scripts Syntax :
Sample Code in php : sample php program
php programmer Code Explanation :
- In PHP, $fruit = "mango"; specifies the variable $fruit = mango variable holding the variable = mango.
- Here, switch ($fruit) will call the variable “$fruit” in the code, which we have specified as “mango”.
- We have the switch-cases as case “apple”, case “mango” and case “guava” which executes based on the function call for that variable ($fruit). If these cases fails it will execute the default case statement.
- break; is the statement that executes a line break in the code execution.
php development Sample Output :
- Here the PHP statement executes the switch condition by printing the echo statement “My favorite fruit is mango”.