carriongrow / formula_parser
Parses formulas, with the possibility of a deferred solution with substitution of user variables
v1.2.0
2025-08-16 18:38 UTC
Requires
- php: >=7.3.0
- ext-json: *
Requires (Dev)
- mockery/mockery: ^1.5
- phpunit/phpunit: ^9
- squizlabs/php_codesniffer: ^3
- vimeo/psalm: ^5
- dev-master
- v1.2.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.9
- v1.0.8
- v1.0.7
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- dev-codex/fix-psalm-errors-at-errorlevel-1
- dev-codex/-psalm-959yn4
- dev-codex/-psalm
- dev-codex/refactor-code-to-comply-with-psr-12
- dev-codex/configure-ci-for-tests-and-code-checks
- dev-codex/create-and-describe-unit-tests-using-phpunit-c0yezz
- dev-codex/create-and-describe-unit-tests-using-phpunit
This package is auto-updated.
Last update: 2025-08-16 18:39:11 UTC
README
Parses formulas, with the possibility of a deferred solution with substitution of user variables
composer require carriongrow/formula_parser
Installation
$ composer require carriongrow/formula_parser
Description
Supported functions basic = '*', '/', '+', '-', '^' functional operations = 'cos', 'sin', 'exp', 'abs', 'log', 'sqrt', 'tan', 'pi'
cos sin tan - Do not require a transfer from degrees to the radian equivalent
Available symbols for dynamic variables: 0-9 a-z _ .or [a-z.0-9_] no dependence on the register!
Example
$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--; }
more look in tests - https://github.com/AnatolySnegovskiy/FormulaParser/blob/master/test/FormulaParserTest.php