1. Home
  2. Computing & Technology
  3. PHP / MySQL

Switch () PHP Function

By Angela Bradley, About.com

Definition: The PHP function switch () is used in place of several IF / ELSEIF statements. The default is optional, and is used if no other case is true. If you do not use a break; then all statements below your original statement will be treated as true.
Also Known As: Switch Loop
Examples:
<?php
switch ($i)
{
case 0:
echo "Zero";
break;
case 1:
echo "One";
break;
case 2:
echo "Two";
break;
default:
echo "Choose a different number";
}
?>

Explore PHP / MySQL

More from About.com

  1. Home
  2. Computing & Technology
  3. PHP / MySQL
  4. PHP Functions
  5. PHP Switch - PHP Switch tutorial - PHP Switch Function

©2008 About.com, a part of The New York Times Company.

All rights reserved.