PHP switch statement

A switch statement is used when you have multiple possibilities for the if statement.

Figure - Flowchart of switch Statement:

php-switch

Example of a PHP Program to Demonstrate Switch Statement

Example:

<?php
$myFavColor='red';
switch ($myFavColor)
{
case 'pink':
  echo 'My favorite car color is pink!';
  break;
case 'red':
  echo 'My favorite car color is red!';
  break;
case 'orange':
  echo 'My favorite car color is orange!';
  break;
default:
  echo 'My favorite car color is not pink, red, or orange!';
}
?>  


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram

Notifications

Updates are enabled for this browser.

Receive new tutorials, articles and learning resources. You can turn updates off anytime.

Test browser code

Use this code in admin to send a test notification to this browser.