Download the PHP package williams/xpression without Composer
On this page you can find all versions of the php package williams/xpression. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download williams/xpression
More information about williams/xpression
Files in williams/xpression
Package xpression
Short Description Evaluate user supplied mathmematical expressions.
License MIT
Informations about the package xpression
Xpression
Xpression is a versatile PHP library designed to evaluate string-formatted mathematical expressions, enabling applications to process user-defined formulas similar to those used in spreadsheet applications.
Key features:
- BODMAS rule support, with full handling of nested brackets for complex expressions.
- Variable substitution, allowing dynamic input and flexible formula construction.
- Comparison operators for evaluating expressions with logical conditions.
- A comprehensive mathematical and logical functions library, easily extendable with custom functions to suit specific application needs.
Xpression empowers developers to integrate advanced formula evaluation seamlessly, making it ideal for finance, engineering, or other domains requiring dynamic calculations.
Installation
Using Composer:
Usage
Getting Started
A simple example showing how Xpression can resolve an expression with just a few lines of code:
Operators
Xpression offers support for common mathematic and comparison operators.
Mathematical Operators
Comparison Operators
Comparison operators return either 1
(True) or 0
(False).
Variables
Xpression provides two ways for using variables in expressions. The with
method allows setting of variable values with an associative array. Alternatively, an on-the-fly lookup can be achieved by using a Variable Resolver.
Using the with
method to set variables:
The affix
method can be used to change how variables are denoted. Supply one parameter to define a prefix:
Alternatively, supply two parameters for encapsulation:
Functions
A number of built-in functions are available. Below is an example using the MIN
function:
If further functionality is required, you can define your own custom functions.
Further Topics
-
Operator Precedence
-
Exception Handling
- Testing