Specifications

switch Statements
The switch statement works in a similar way to the if statement, but allows the condition to
take more than two values. In an if statement, the condition can be either true or false. In a
switch statement, the condition can take any number of different values, as long as it evaluates
to a simple type (integer, string, or double). You need to provide a case statement to handle
each value you want to react to and, optionally, a default case to handle any that you do not
provide a specific case statement for.
Bob wants to know what forms of advertising are working for him. We can add a question to
our order form.
Insert this HTML into the order form, and the form will resemble Figure 1.6:
<tr>
<td>How did you find Bob’s</td>
<td><select name=”find”>
<option value = “a”>I’m a regular customer
<option value = “b”>TV advertising
<option value = “c”>Phone directory
<option value = “d”>Word of mouth
</select>
</td>
</tr>
PHP Crash Course
C
HAPTER 1
1
PHP CRASH
COURSE
41
FIGURE 1.6
The order form now asks visitors how they found Bob’s Auto Parts.
03 7842 CH01 3/6/01 3:39 PM Page 41