Create A Simple Calculator in PHP

php is the most famous language in programming world and also 70% websites created in php
language because it is also server side language so  Today’s tutorial in PHP is gonna be about that how to create A Simple Calculator in php by 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 that who learn php from basic because it is very simple code or you can say it is like Calculator Demo... you can also read following Post. ajax in php  & Error Reporting in php 


simple-calculator-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 create A simple Calculator in php


How to Create A Simple 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 blow Code and Paste to your File

3.and open in browser 


this Calculator by if else Condition 
========================================================================

this code is very simple for beginners because who could practice on to make own good calculator

so it is just by if and else condition with  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; }?>
====================================================================


A Simple Calculator in Php By Switch Condition 

this is also calculator code but this code created by switch condition not in if and if else condition...  

<?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 swtich condition but this is in webform you can say 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";
                }

?>

COMMENTS

Name

Blogging,5,How to,9,Make Money,4,SEO,4,Tricks & Tips,4,Web Designing,10,Web Development,5,
ltr
item
Web Log Tricks: Create A Simple Calculator in PHP
Create A Simple Calculator in PHP
How Create A Simple Calculator in PHP with basic calculator functions using switch case and also web forms button tutorials code and script,
https://4.bp.blogspot.com/--FYiLKqXGXs/WKP5NOdWuaI/AAAAAAAAAVA/7ChIHUHtMGEj_uzhrTF45mh-lKe41crxACLcB/s640/Presentation1.jpg
https://4.bp.blogspot.com/--FYiLKqXGXs/WKP5NOdWuaI/AAAAAAAAAVA/7ChIHUHtMGEj_uzhrTF45mh-lKe41crxACLcB/s72-c/Presentation1.jpg
Web Log Tricks
http://www.weblogtricks.com/2017/02/create-simple-calculator-in-php.html
http://www.weblogtricks.com/
http://www.weblogtricks.com/
http://www.weblogtricks.com/2017/02/create-simple-calculator-in-php.html
true
3158682668530211189
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy