Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

README.md

Build Status Coverage Status Dependency Status

Math

for PHP

I created this just for fun, but I made a little twist to it. - MathML markup

So if you do this

<?php
require __DIR__ . '/vendor/autoload.php';

use Math\Basic;
use Math\Calculations\Calculation;
use Math\Calculations\Calculations;

$c = new Calculations();
$o = new Basic($c, 2); // Sets our calculator table and our starting number
$o->add(20) // Adding 20
    ->sub(10) // Substract 10
    ->divide(2) // And divide by 2
    ->multiply(2) // And of course we multiply it again
    ->factorial(2) // Now we get the factorial
    ->setNumber(7) // Here we reset our default number
    ->square() // Take the square of the number
    ->modulus(2); // And get the modulus

foreach($c->get() as $calc) {
    /** @var Calculation $calc */
    echo $calc->getStartTag(array('display' => 'block'));
    echo sprintf('%s<mo>=</mo><mn>%s</mn>', $calc->getMath(), $calc->getResult());
    echo $calc->getEndTag();
}

You will end up with this

<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>2</mn>
  <mo>+</mo>
  <mn>20</mn>
  <mo>=</mo>
  <mn>22</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>22</mn>
  <mo>-</mo>
  <mn>10</mn>
  <mo>=</mo>
  <mn>12</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>12</mn>
  <mo>/</mo>
  <mn>2</mn>
  <mo>=</mo>
  <mn>6</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>6</mn>
  <mo>x</mo>
  <mn>2</mn>
  <mo>=</mo>
  <mn>12</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>12!</mn>
  <mo>=</mo>
  <mn>479001600</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>7</mn>
  <msup>
    <mi>^2</mi>
  </msup>
  <mo>=</mo>
  <mn>49</mn>
</math>
<math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
  <mn>49</mn>
  <mo>%</mo>
  <mn>2</mn>
  <mo>=</mo>
  <mn>1</mn>
</math>

And this is how it looks in the browser

Screenshot

Im not an expert in either math or MathML, so if I made some booboos, add an issue - I will add more calculations soon or later.

Something went wrong with that request. Please try again.