php中使用switch分支语句范例
<?php //Initializing variables $a = 10; $b = 5; echo("1. Addition <br>"); echo("2. Subtraction <br>"); echo("3. Multiplication <br>"); echo("4. Division <br>"); $ch=3; switch ($ch) { case 1: $d=$a+$b; echo("The sum of the two numbers is $d"); break; case 2: $d=$a-$b; echo("The difference of the two numbers is $d"); break; case 3: $d=$a*$b; echo("The product of the two numbers is $d"); break; case 4: $d=$a/$b; echo("The quotient of the two numbers is $d"); break; default: echo("Incorrect Option"); break; } ?>