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   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-05-24 (4 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 41 All time: 10,870 This week: 50Up
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: 25 packages by
Country: Nigeria Nigeria
Age: ???
All time rank: 274719 in Nigeria Nigeria
Week rank: 21 Up2 in Nigeria Nigeria Up
Innovation award
Innovation award
Nominee: 15x

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 (7)  
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 (7)  /  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 (7)  /  include  /  class  
File Role Description
  Plain text file Operator.php Class Class source

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

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:41
This week:0
All time:10,870
This week:50Up