Home >> PHP - MySQL Programming with PHP 2.1 [Page 7] Article by: Shelton Manage Tuesday, 26th May, 2009
Switch
PHP has another type of cpnditional, call the switch.
switch ($variable) { case 'value1': // Do this. break; case 'value2': // Do this. break; default: // Do this. break; }
Ex: switch ($gender) { case 'M': echo '
Good day, Sir!
'; break; case 'F': echo '
Good day, Madam!
'; break; default: echo '
You forget enter your gender!
'; break; }
Ex: switch.phps
The switch conditional is limited in its usage in that it can only check a variables value for equality against certain cases; more complex conditions cannot be used.
Page: First - 1 2 3 4 5 6 7 8 9 10 - Last
|