PHP Classes

How to Implement a PHP Calculator for Basic Math Operations using the Package Simple OOP PHP Calculator: Perform simple math operations between two numbers

Recommend this page to a friend!
  Info   View files Example   View files View files (7)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-05-24 (8 days ago) RSS 2.0 feedNot yet rated by the usersTotal: 35 This week: 17All time: 10,966 This week: 5Up
Version License PHP version Categories
simple-oop-php-calcu 1.0The PHP License5PHP 5, Math
Description 

Author

This package can perform simple math operations between two numbers.

It provides a function that takes as parameters two numbers and the name of an operation.

The function checks the function name and performs the respective math operation with the numbers to return the operation result.

Currently, it supports addition, subtraction, multiplication, and division.

Picture of Adeleye Ayodeji
  Performance   Level  
Name: Adeleye Ayodeji <contact>
Classes: 19 packages by
Country: Nigeria Nigeria
Innovation award
Innovation award
Nominee: 13x

Example

<?php
 
include 'autoload.php';

  if (isset(
$_POST["add"])) {
   
//Getting values from ajax
   
$operator = $_POST["operator"];
   
$field1 = $_POST["field1"];
   
$field2 = $_POST["field2"];
   
//Loading anwser to page
    //Object
   
$answer = new Operator($operator,$field1,$field2);
   
$result = $answer->calculator();
   
//Getting operator type
   
if ($operator == "add") {
     
$opera = "#007bff";
     
$color = "white";
     
$sign = "+";
    }elseif (
$operator == "sub") {
     
$opera = "black";
     
$color = "white";
     
$sign = "-";
    }elseif (
$operator == "mul") {
     
$opera = "#600b4a";
     
$color = "white";
     
$sign = "*";
    }elseif (
$operator == "div") {
     
$opera = "blueviolet";
     
$color = "white";
     
$sign = "/";
    }
   
//Converting to json
   
$jsonresult = array("bg"=>$opera, "result"=>$result, "color"=>$color, "sign"=>$sign);
    echo
json_encode($jsonresult);
  }else{
    echo
"Am not set";
  }
 
?>


Details

Simple-OOP-PHP-Calculator

Object Oriented Programming has always been fun with the right basic tools, get started with OOP using basic tools of mine


  Files folder image Files  
File Role Description
Files folder imageinclude (2 files, 1 directory)
Files folder imagejs (1 file)
Accessible without login Plain text file index.php Aux. Auxiliary script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  include  
File Role Description
Files folder imageclass (1 file)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script
  Accessible without login Plain text file Result.php Example Example script

  Files folder image Files  /  include  /  class  
File Role Description
  Plain text file Operator.php Class Class source

  Files folder image Files  /  js  
File Role Description
  Accessible without login Plain text file core.js Data Auxiliary data

 Version Control Unique User Downloads Download Rankings  
 100%
Total:35
This week:17
All time:10,966
This week:5Up