switch in php

The switch statement works in a similar way to the if statement, but it 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 float)

Example of switch in php

switch($find) {
 case "a" :
 echo "<p>Regular customer.</p>";
 break;
 case "b" :
 echo "<p>Customer referred by TV advert.</p>";
 break;
 case "c" :
 echo "<p>Customer referred by phone directory.</p>";
 break;
 case "d" :
 echo "<p>Customer referred by word of mouth.</p>";
 break;
 default :
 echo "<p>We do not know how this customer found us.</p>";
 break;
}

Leave a Comment