PHP code example of denissimon / formula-parser
1. Go to this page and download the library: Download denissimon/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/ */
denissimon / formula-parser example snippets
php
e FormulaParser\FormulaParser;
$formula = '3*x^2 - 4*y + 3/y';
$precision = 2; // Number of digits after the decimal point
try {
$parser = new FormulaParser($formula, $precision);
$parser->setVariables(['x' => -4, 'y' => 8]);
$result = $parser->getResult(); // [0 => 'done', 1 => 16.38]
} catch (\Exception $e) {
echo $e->getMessage(), "\n";
}
php
$parser = new FormulaParser('3+4*2/(1-5)^8');
$result = $parser->getResult(); // [0 => 'done', 1 => 3.0001]