PHP code example of williams / xpression

1. Go to this page and download the library: Download williams/xpression library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

williams / xpression example snippets



use Williams\Xpression\Xpression;

$xp = Xpression::new();
echo $xp->evaluate('2*3+4'); // 10

$maths = [
    "4^2", // 16 - Powers
    "9/3", // 3  - Division
    "7*5", // 35 - Multiplication
    "5+2", // 7  - Addition
    "4-3", // 1  - Subtracton
];

$comparisons = [
    "2=2",  // 1  - Equal to
    "4<3",  // 0  - Less Than
    "5>2",  // 1  - Greater Than
    "7<=7", // 1  - Less Than or Equal To
    "8>=9", // 0  - Greater Than or Equal to
    "2<>6", // 1  - Not Equal To
];

// Example using variables:
$xp->with([
 'a' => 7,
 'b' => 5
]);

echo $xp->evaluate('$a-$b'); // 2

$xp->affix('%');
echo $xp->evaluate('%a-%b');

$xp->affix('{','}');
echo $xp->evaluate('{a}-{b}');

echo $xp->evaluate('MIN($a,$b)'); // 5