PHP is the most famous language in the programming world and also 70% of websites created by PHP language because it is also server-side language.
So today’s tutorial is about how to Make a calculator program in PHP using switch case and Arithmetic operators in PHP.
This is something you can easily do by practicing basic arithmetic operations in PHP because I write this post for those people who are learning from basic.
it is very simple code or you can say it is like Calculator Demo... you can also read the following Posts.
ajax in PHP & Error Reporting in PHP
So today’s tutorial is about how to Make a calculator program in PHP using switch case and Arithmetic operators in PHP.
This is something you can easily do by practicing basic arithmetic operations in PHP because I write this post for those people who are learning from basic.
it is very simple code or you can say it is like Calculator Demo... you can also read the following Posts.
ajax in PHP & Error Reporting in PHP
Conditional statements are the set of commands used to perform different actions based on different
conditions. In PHP we have the following conditional statements for Making Calculator in PHP.
How to Make a Calculator in PHP?
1. Open notepad and create a new file save as "calculator.php" or any name as u like you can write
2. copy below Code and Paste to your file
3. open in the browser simply.
3. open in the browser simply.
I also tell you about two methods of creating in which you can create a simple calculator with the help of programming Code.
1.Making a Calculator by if-else Condition
========================================================================
this code is very simple for beginners because who could practice on to make an own good calculator
so it is just by if and else condition with the arithmetic operation.
this code is very simple for beginners because who could practice on to make an own good calculator
so it is just by if and else condition with the arithmetic operation.
<?php $input1 = 10;$input2 = 17; $op = "-"; if ($op=="+"){ echo "Your Plus Marks = "; echo $input1 + $input2; }
elseif ($op=="-")
{ echo " Your Subtrator Marks = "; echo $input1 - $input2; }
elseif ($op == "*"){ echo "Multiplation marks = "; echo $input1 * $input2; }
else if($op =="/"){echo "divion marks = "; echo $input1 / $input2; }?>
====================================================================
2. Calculator program in PHP using switch case
<?php $input1 = 10;$input2 = 15;$op = "/";
switch($op) { case '+': echo "Your Result ="; echo $input1 + $input2 ; break; case '-': echo "Your Result = ";echo $input1 - $input2; break; case '*': echo "Your Result = ";echo $input1 * $input2; break; case '/': echo "Your Result = ";echo $input1 / $input2; break; default: echo "default"; }
?>
========================================================================
PHP Script
This code also in switch condition but this is in web form you can say the shape of styling calculator
<?php
$input1 = $_POST["num1"];
$input2 = $_POST["num2"];
$op = $_POST["operator"];
switch($op)
{
case '+':
echo "Your Result =";
echo $input1 + $input2 ;
break;
case '-':
echo "Your Result = ";
echo $input1 - $input2;
break;
case '*':
echo "Your Result = ";
echo $input1 * $input2;
break;
case '/':
echo "Your Result = ";
echo $input1 / $input2;
break;
default:
echo "default";
}
?>
If you have any Question you can ask me.
COMMENTS