Description
MathExecutor is a PHP library that parses and evaluates math expressions, and it is designed to be extended. It supports the operators +, -, *, /, % and power (^), with parentheses and arrays, and logical operators such as ==, != and =. You can add your own functions to the executor, such as a round function with a precision argument or an average function that takes any number of arguments. You can also define your own operators with a sign, an associativity, a priority and a PHP callback, for example to add a custom modulo. Variables can be used with or without the dollar sign prefix. Default variables are provided, and you can add your own. Arrays can be used as variables and as function arguments, and they can be returned from user functions. A variable validation handler can accept types beyond scalars and arrays, and an undefined-variable handler lets you compute values only when they are used. The library is installed with Composer and is aimed at PHP developers who need user-supplied formulas, for example in calculators, pricing rules or configuration.…
Highlights
- Operators, parentheses, arrays and logical operators
- Custom PHP functions
- Custom operators with priority
- Variables and undefined-variable handler
- Installed with Composer
Ratings & Reviews
No ratings yet
Be the first to rate MathExecutor.
People also visit

MathParser.org-mXparser
Math Parser: Java, C#, C++, Kotlin, Android, and all .NET platforms
MathExecutor FAQ
What is MathExecutor?
A PHP library that parses and calculates math expressions and can be extended.
How do I install it?
Install it with Composer, as shown in the README.
Can I add my own functions?
Yes. The README shows addFunction with examples such as round and average.
Can I add operators?
Yes. An operator takes a sign, an associativity flag, a priority and a PHP function, as the README's modulo example shows.
Which operators are built in?
+, -, *, /, %, power (^), parentheses, arrays and logical operators.
What are the best MathExecutor alternatives?
Popular alternatives to MathExecutor include MathParser.org-mXparser, ExpressionEvaluator and Tinyexpr. See all MathExecutor alternatives







