PHP code example of phpmyadmin / simple-math

1. Go to this page and download the library: Download phpmyadmin/simple-math library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

phpmyadmin / simple-math example snippets


// Create math object
$math = new SimpleMath\Math();

// Evaluate expression
$value = $math->evaluate('1 + 2');

// Evaluate expression with PHP style variable
$math->registerVariable('$a', 4);
$value = $math->evaluate('$a + 1');

// Evaluate expression with variable
$math->registerVariable('n', 4);
$value = $math->evaluate('n + 1');

// Calculate same expression with different values
$math = new SimpleMath\Math();

$math->parse('n + 1');

$math->registerVariable('n', 10);
$value = $math->run();

$math->registerVariable('n', 100);
$value = $math->run();