✖️➕➖➗ `math_eval` safely evaluates mathematical expressions
Installs: 230 458
Open Issues: 3
- php: >=5.6
- mossadal/math-parser: ^1.3
- fzaninotto/faker: ^1.6
- php-coveralls/php-coveralls: ^2.0
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2023-03-20 16:13:35 UTC
This PHP package provides a
math_eval helper function, that
allows safe evaluation of mathematical expressions, without the use of the
math_eval package can be easily installed using Composer. Just
run the following command from the root of your project.
composer require "langleyfoxall/math_eval"
If you have never used the Composer dependency manager before, head to the Composer website for more information on how to get started.
To evaluate a basic mathematical expression, just pass its string
representation to the
Here are some basic usage examples:
$two = math_eval('1 + 1'); $three = math_eval('5 - 2'); $ten = math_eval('2 * 5'); $four = math_eval('8 / 2');
It is also possible to pass expression variables. See the examples below.
$ten = math_eval('a + b', ['a' => 7, 'b' => 3]); $fifteen = math_eval('x * y', ['x' => 3, 'y' => 5]);
This package makes use of the