PHP code example of carriongrow / formula_parser
1. Go to this page and download the library: Download carriongrow/formula_parser 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/ */
carriongrow / formula_parser example snippets
$parser = new FormulaParser();
$parser->setFormula('test1 * test2 * 2 (1 + 10) / 20'); // Parsing formulas once
$counter = 1000;
$result = [];
while ($counter != 0) { // We use it as many times as we need
$first = rand(1, getrandmax()) / getrandmax();
$second = rand(1, getrandmax()) / getrandmax();
$parser->setVariables(['test1' => $first, 'test2' => $second]); // Replacing user variables with values
$result[] = $parser->calculate();
$counter--;
}