Core feature

Grammar & precedence

Build expressions people can read: numbers, variables, grouping, operators, and deliberate precedence.

← All documentation

From text to a typed result.

MathPHP accepts a small expression language and turns it into an immutable AST before evaluation. Multiplication binds tighter than addition, exponentiation is right-associative, and unary signs have explicit rules.

$result = Math::evaluate('gross * (1 - discount)', ['gross' => 125, 'discount' => 0.2]);
Try it:2^3^2 is 512; -2^2 is -4.