PHP Classes

File: include/Result.php

Recommend this page to a friend!
  Classes of Adeleye Ayodeji   Simple OOP PHP Calculator   include/Result.php   Download  
File: include/Result.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Simple OOP PHP Calculator
Perform simple math operations between two numbers
Author: By
Last change:
Date: 3 months ago
Size: 1,001 bytes
 

Contents

Class file image Download
<?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";
  }
 
?>