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

Switch () PHP Function

By , About.com Guide

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
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

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

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

All rights reserved.