承接 rossonero585/php-expression 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rossonero585/php-expression

Composer 安装命令:

composer require rossonero585/php-expression

包简介

Simple library for calculating math expressions

README 文档

README

Description

This library allows creating math expression using numbers, brackets, mathematical signs (+,-,*,/) and then execute them with different arguments. It also allows adding custom functions to be executed inside expression. It works trough eval function that receives dynamically generated string and then run it.

Example usage

Simple expression

<?php

$expressionBuilder = new \Rossonero585\PhpExpression\ExpressionBuilder();

$expression = $expressionBuilder
    ->addArguments(['a', 'b'])
    ->create('a + b');

echo $expression->execute(["a" => 5, "b" => 5]);
// 10

echo $expression->execute(["a" => 2, "b" => 1]);
// 3

Add custom function

<?php

$expressionBuilder = new \Rossonero585\PhpExpression\ExpressionBuilder();

$expression = $expressionBuilder
    ->addFunction('convert', function ($value, $curr1, $curr2) {
        // do some stuff here
        return 61;
    })
    ->addArguments(["x", "curr1", "curr2"])
    ->create('1.1 * convert(x, curr1, curr2) + 100');

$result = $expression->execute([
    "x" => 100,
    "curr1" => "USD",
    "curr2" => "RUB"
]);

统计信息

  • 总下载量: 7
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固