<?php
// STRUCTURE #1
switch (var)
{
case val 1:
statement 1
break;
case val 2:
statement 2
break;
. . . . . . . . . . . .
case val J:
statement J
break;
. . . . . . . . . . . .
default:
default statement
}
?>
<?php
// STRUCTURE #2
switch (var):
case val 1:
statement 1
break;
case val 2:
statement 2
break;
. . . . . . . . . . . .
case val J:
statement J
break;
. . . . . . . . . . . .
default:
default statement
endswitch;
?>
<?php
// STRUCTURE #3
switch (var)
{
case val 1;
case val 2;
case val 3;
. . . . . . . .
case val J;
. . . . . . . .
statement 123
break;
default:
default statement
break;
}
?>
SOLVE ALL PROPOSED EXERCISES
NOT SOLVED YET
If possible in several versions of PHP
Especially the latest 7 and 8
Study the displayed data carefully
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Data collected by some input process
in the variable $d01
- - - - - - - - - - - - - - - - - - - - - - - */
$d01 = 'Isaac Newton';
switch ($d01)
{
case 'Socrates':
echo $d01 . ', the philosopher!';
break;
case 'Isaac Newton':
echo $d01 . ', the physicist!';
break;
case 'Mariah Carey':
echo $d01 . ', the singer!';
break;
default:
echo 'Not related!';
}
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Data collected by some input process
in the variable $d02
- - - - - - - - - - - - - - - - - - - - - - - */
$d02 = 'Socrates';
switch ($d02):
case 'Socrates':
echo $d02 . ', the philosopher!';
break;
case 'Isaac Newton':
echo $d02 . ', the physicist!';
break;
case 'Mariah Carey':
echo $d02 . ', the singer!';
break;
default:
echo 'Not related!';
endswitch;
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Data collected by some input process
in the variable $d03
- - - - - - - - - - - - - - - - - - - - - - - */
$d03 = 'Mariah Carey';
switch ($d03)
{
case 'Socrates';
case 'Isaac Newton';
case 'Mariah Carey';
echo $d03 . ', Is related!';
break;
default:
echo 'Not related!';
}
?>
<?php
/* - - - - - - - - - - - - - - - - - - - - - - -
Data collected by some input process
in the variable $d04
- - - - - - - - - - - - - - - - - - - - - - - */
$d04 = 'Red';
switch ($d04):
case 'Red';
case 'Green';
case 'Blue';
echo $d04 . ', Is related!';
break;
default:
echo 'Not related!';
endswitch;
?>