terryds / express-math
A parser for its own math or computational problem markup language
dev-master
2018-07-08 08:56 UTC
Requires
- mossadal/math-parser: ^1.3
This package is not auto-updated.
Last update: 2025-03-25 19:45:19 UTC
README
ExpressMath is a parser for its own math/computational problem markup language.
The markup language is inspired from Jinja template.
See example for better understanding of how this works
Installing
ExpressMath installation using Composer
composer require terrydjony/express-math
Example
require 'vendor/autoload.php'; use ExpressMath\ExpressMath; $mathlang = 'Jika Andi punya {{ a }} bola, dan Budi punya {{ b }} bola, maka jumlah bola mereka adalah {% a + b %}'; $config = [ 'a' => mt_rand(2,5) ]; $expressMath = new ExpressMath(); $eval = $expressMath->eval($mathlang, $config); var_dump($eval->getProblem()); // Jika Andi punya 4 bola, dan Budi punya 56 bola, maka jumlah bola mereka adalah var_dump($eval->getVariables()); // ['a' => 4, 'b' => 56] var_dump($eval->getValue()); // 60