Use the ‘default’ case

<?php
$nIndex = 17;
switch ( $nIndex )
{
case 0:
print( "zero<br>" );
break;
case 1:
print( "one<br>" );
break;
case 2:
print( "two<br>" );
break;
default:
print( "neither zero, one nor two<br>" );
break;
}
?>

Using switch to test for multiple values
<?php
$action = "ADD";
switch ($action) {
case "ADD":
echo "Perform actions for adding.";
break;
case "MODIFY":
echo "Perform actions for modifying.";
break;
case "DELETE":
echo "Perform actions for deleting.";
break;
}
?>

0 comments:

Post a Comment

 
Top
Blogger Template