PHP code example of rodriados / mathr

1. Go to this page and download the library: Download rodriados/mathr 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/ */

    

rodriados / mathr example snippets



$mathr = new Mathr;
$result = $mathr->evaluate("3 + 4 * 5");
echo $result; // 23


$mathr->evaluate("v = 10");
$mathr->evaluate("fibonacci(0) = 0");
$mathr->evaluate("fibonacci(1) = 1");
$mathr->evaluate("fibonacci(x) = fibonacci(x - 1) + fibonacci(x - 2)");
$result = $mathr->evaluate("fibonacci(v)");
echo $result; // 55


$mathr->set('triangle(b, h)', fn ($b, $h) => ($b * $h) / 2);
$result = $mathr->evaluate('triangle(5, 8)');
echo $result; // 20


$mathr->evaluate("fibonacci(x) = ceil((φ ^ x - (1 - φ) ^ x) / sqrt(5))");
$result = $mathr->evaluate("fibonacci(10)");
echo $result; // 55


$exported = $mathr->export(); // Exports all bound functions and variables.
$mathr->import($exported); // Imports functions and variables.