genimi / calculater
Calculater library for php
v1.0.1
2021-01-20 02:41 UTC
Requires
- php: >=7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.18
- phpstan/phpstan: ^0.12.68
- phpunit/phpunit: >=5.6
This package is auto-updated.
Last update: 2024-11-20 16:17:38 UTC
README
安装
composer require genimi/calculater
使用
<?php use Know\Calculater\Calculater; $params = [ 1 => 1, 2 => 4, 3 => 6, 4 => 16, 5 => 100, ]; $calculater = new Calculater(); $string = '+ (1) (+ (1) (2))'; $result = $calculater->calculate($string, $params); // 6 $string = '++ 1 3'; $result = $calculater->calculate($string, $params); // 11 // 对应的选项 $extParams = [ 1 => 0, 2 => 1, 3 => 1, 4 => 0, 5 => 2, ]; //(数字①-数字②)代表第①题的选项②(②从0开始,按顺序计。用户选此选项计单项分,未选不计) $string = '+ (1) (+ (1-1) (2-1))'; // 1 + 0 + 4 $result = $calculater->calculate($string, $params, $extParams); // 5