对php中使用switch分支语句范例感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编两巴掌来看看吧!
/**
* php中使用switch分支语句范例
*
* @param
* @arrange 512-笔记网: www.www.jb51.cc
**/
<?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;
}
/*** 来自编程之家 jb51.cc(jb51.cc) ***/