PHP code example of 4slovo / expression
1. Go to this page and download the library: Download 4slovo/expression 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/ */
4slovo / expression example snippets
$expressionText = '$radius = 2; $area = 3.14 * ($radius ** 2);';
$codeContext = new CodeContext();
$codeExecutor = new CodeExecutor();
$variableName = '$result';
$areaResult = $codeExecutor
->setCode($expressionText)
->setCodeContext($codeContext)
->execute()
->getVariableByName('$area');
echo $areaResult; # выведет 12.56