PHP switch case Statement - PHP Tutorial 43

preview_player
Показать описание
Notes for You:: PHP switch case Statement - PHP Tutorial 43
When there are more than one alternative choices present, we use switch case statement.
PHP engine executes the case whose label matches the expression given in a switch parenthesis.
syntax:
switch(expression)
{
case label-1:
statements;
break;
case label-2:
statements;
break;

default:
statements;
break;
}

OR

switch(expression):
case label-1:
statements;
break;
case label-2:
statements;
break;

default:
statements;
break;
endswitch;

Example Code:

$day = -10;

switch($day)
{
case 1: echo "Sunday","<br/>";
break;
case 2: echo "Monday","<br/>";
break;
case 3: echo "Tuesday","<br/>";
break;
case 4: echo "Wednesday","<br/>";
break;
case 5: echo "Thursday","<br/>";
break;
case 6: echo "Friday","<br/>";
break;
case 7: echo "Saturday","<br/>";
break;
default: echo "Invalid day","<br/>";
break;
}
echo "Outside switch";
OR

$day = 4;

switch($day):
case 1: echo "Sunday","<br/>";
break;
case 2: echo "Monday","<br/>";
break;
case 3: echo "Tuesday","<br/>";
break;
case 4: echo "Wednesday","<br/>";
break;
case 5: echo "Thursday","<br/>";
break;
case 6: echo "Friday","<br/>";
break;
case 7: echo "Saturday","<br/>";
break;
default: echo "Invalid day","<br/>";
break;
endswitch;
echo "Outside switch";

Note:
- replace < with less-than symbol.
- replace > with greater-than symbol.

=========================================

Follow the link for next video:
PHP Tutorial 44 - for Loop in PHP | PHP for Loop Tutorial

Follow the link for previous video:
PHP Tutorial 42 - Find grade of a student using if else if statement in JavaScript

=========================================

PHP Tutorials Playlist:-

=========================================
Watch My Other Useful Tutorials:-

MySQL Tutorials Playlist:-

HTML Tutorials Playlist:-

CSS Tutorials Playlist:-

JavaScript Tutorials Playlist:-

=========================================

► Subscribe to our YouTube channel:

► Visit our Website:

=========================================
Hash Tags:-
#ChidresTechTutorials #PHP #PHPTutorial
Рекомендации по теме
Комментарии
Автор

SUBSCRIBE, SHARE & SUPPORT:
VISIT & LEARN AT FREE OF COST:

ChidresTechTutorials