PHP code example of anastasd / expression-parser

1. Go to this page and download the library: Download anastasd/expression-parser 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/ */

    

anastasd / expression-parser example snippets



$settings = new Settings(Settings::PHP);
$parser = new Parser($settings);

$input = '-pow($a, 2) * sin(log($b)) + cos(sqrt($c)) * exp(tan($d)) / log(abs($e)) - sqrt(pow($f, 3))';

echo $parser->parse($input, ['$a', '$b', '$c', '$d', '$e', '$f'])
     ->prepare()
     ->compile();


$settings = new Settings(Settings::PHP);
$parser = new Parser($settings);

$input = '-pow($a, 2) * sin(log($b)) + cos(sqrt($c)) * exp(tan($d)) / log(abs($e)) - sqrt(pow($f, 3))';

echo $parser->parse($input, ['$a', '$b', '$c', '$d', '$e', '$f'])
     ->prepare()
     ->evaluate([1, 2, 3, 4, 5, 6]);