Home > Backend Development > PHP Tutorial > Simple calculator implementation code for PHP learning_PHP tutorial

Simple calculator implementation code for PHP learning_PHP tutorial

WBOY
Release: 2016-07-21 15:28:47
Original
827 people have browsed it

Copy code The code is as follows:



PHP implementation is simple Calculator


//Single-way branch
if(isset($_GET["sub"]))
{
$num1=true;//Whether number 1 is an empty mark
$num2= true;//Whether number 2 is a null mark
$numa=true;//Whether number 1 is a number
$numb=true;//Whether number 2 is a digit
$message="";
//Determine whether number 1 is empty
if($_GET["num1"]=="")
{
$num1=false;
$message.="First one The number cannot be empty";
}
//Determine whether number 1 is a number
if(!is_numeric($_GET["num1"]))
{
$numa=false;
$message.="The first number is not a number";
}
//Determine whether number 2 is a number
if(!is_numeric($_GET["num2"]))
{
$numa=false;
$message.="The second number is not a number";
}
//Determine whether number 2 is empty
if($_GET[" num2"]=="")
{
$num2=false;
$message.="The second number cannot be empty";
}
if($num1 && $ num2 && $numa && $numb)
{
$sum=0;
//Multi-way branch
switch($_GET["ysf"]){
case "+":
$sum=$_GET["num1"]+$_GET["num2"];
break;
case "-":
$sum=$_GET["num1"]-$ _GET["num2"];
break;
case "x":
$sum=$_GET["num1"]*$_GET["num2"];
break;
case "/":
$sum=$_GET["num1"]/$_GET["num2"];
break;
case "%":
$sum=$_GET[" num1"]%$_GET["num2"];
break;
}
}
}
?>










if( isset($_GET["sub"]))
{
echo '';
}
?>

calculator


">



">


';
if($num1 && $num2 && $numa && $numb)
{
echo "The result is: ".$_GET["num1"]." ".$_GET["ysf"]." ".$_GET["num2"]." = " .$sum;
}
else
{
echo $message;
}
echo '




Simple calculator implementation code for PHP learning_PHP tutorial

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323562.htmlTechArticleCopy the code as follows: html head titlePHP implements a simple calculator/title meta http-equiv="Content-Type" content="text/html;charset=gb2312" /head ?php //Single branch if(isset($_GET[...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template