Blogger Information
Blog 6
fans 0
comment 0
visits 3766
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
1119 PHP基础作业
开吉尔软件
Original
647 people have browsed it

1119 PHP基础作业:

使用条件分支结构与php运算符模拟实现基本的简单的计算器功能~

// 定义3个变量
$a = 4; //操作数1
$b = 2; //操作数2
$res = 0; //保留计算结果
//定义+ - / 字符串
$calc =’+’;
//加法运算
if ($calc === ‘+’){
$res = $a + $b;
echo $a.$calc.$b.’=’.$res;
}
//减法运算
elseif ($calc === ‘-‘){
$res = $a - $b;
echo $a.$calc.$b.’=’.$res;
}
//乘法运算
elseif ($calc === ‘
‘){
$res = $a * $b;
echo $a.$calc.$b.’=’.$res;
}
//除法法运算
elseif ($calc === ‘/‘){
$res = $a / $b;
echo $a.$calc.$b.’=’.$res;
}
else {
echo ‘超过我的计算能力!’;
}

?>

Correcting teacher:灭绝师太灭绝师太

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
1 comments
灭绝师太 2020-11-20 14:49:26
这个计算器是够简单的~但我们也算是学以致用了~但还有进步空间~
1 floor
Author's latest blog post