![]() |
Switch Statement with output in php |
How to use a switch statement with output in PHP
Switch statement: Switch statement allows us to execute one statement from many statements and the statements are called cases.
The PHP switch statement is used to execute one statement from
multiple conditions. It works like a PHP if-else-if statement. Inside the body of the switch, there are some cases and there is a single number is passed at
the place of the parameter to select and execute a case.
Some Others Programming Language Switch Statement
Some Important Points To Be Switch Case in PHP:
1. The default is an optional statement. Even it is not important, the default must always be the last statement. |
Switch Statement Syntax in PHP
switch(expression) { |
Switch statement a value and number are passed in
the place of parameter and the case from which the parameter is matched is
executed. If no case matched with the parameter then the default case will execute.
How To Use Switch Statement Week Program in PHP?
<?php $day=5;
switch($day) { case 1: echo "Monday"; break; case 2: echo "Tuesday"; break; case 3: echo "Wednesday"; break; case 4: echo "Thursday"; break; case 5: echo "Friday"; break; case 6: echo "Saturday"; break; case 7: echo "Sunday"; break; default: echo "No case matched"; } ?> *****OUTPUT***** Friday |
How To Check Given Alphabet is vowel or Consonant in PHP?
<?PHP
$ch = 'O'; switch ($ch) { case 'a': break;
break;
break; echo "Given character is the vowel";
case ' u ': echo "Given character is the vowel"; echo "Given character is the vowel"; echo "Given character is consonant"; |
How To Use Number Switch Statement in PHP?
<?PHP { *****OUTPUT***** |
How To Use Switch Statement with String in PHP?
<?PHP switch ($ch) *****OUTPUT***** |
Nested Switch Statement: A Nested
switch statement means switch statement inside another switch statement in PHP.
How To Use Nested Switch Statement in PHP?
<?PHP switch( $car ) echo "Honda Amaze"; case "Kwid": echo "Hyundai Xcent"; |