hoanglongtrinh/logic-expression 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hoanglongtrinh/logic-expression

最新稳定版本:v1.7

Composer 安装命令:

composer require hoanglongtrinh/logic-expression

包简介

Excel-like logic functions for PHP (IF, IFS, AND, OR...) with lazy evaluation & string parser

README 文档

README

A lightweight PHP library that mimics Excel's logical expressions.

Supported functions

  • if_excel(condition, valueIfTrue, valueIfFalse)
  • ifs_excel(condition1, value1, ..., conditionN, valueN)
  • and_excel(...)
  • or_excel(...)
  • not_excel(...)

Installation

composer require hoanglongtrinh/logic-expression

use

use LogicExpression\Logic;

$logic = new Logic();

$result = $logic->IF(
    fn() => 1 == 1,
    fn() => 'YES',
    fn() => 'NO'
); // 👉 'YES'


use LogicExpression\LogicParserService;

$parser = LogicParserService::getInstance();

$result = $parser->IFS(
    1 == 2, 100,
    $parser->IF(3 == 3, 200, 300),
    1
); // 👉 200


use function parseAllLogicExpressions;
$messages = [
    'ifs_excel' => 'Lỗi logic phân loại khách hàng',
    'if_excel'  => 'Sai biểu thức điều kiện IF tại bước xác minh',
    'and_excel' => 'AND không hợp lệ khi kết hợp điều kiện doanh số',
    'or_excel'  => 'OR bị lỗi trong phân tích KPI',
    'not_excel' => 'NOT dùng sai trong lọc báo cáo'
];

$expr = "IFS(1=2, 4, IF(3=1, 4, 0), IF(IF(3=3,7,0)=0,3,5)=5, 2, 1)";
echo parseAllLogicExpressions($expr, $messages); // 👉 "2"


$input = "IFS(1=2, 4, IF(3=1, 4, 0), IF(IF(3=3,7,0)=0,3,5)=5, 2, 1) + AND(1=1, 2=2)";
$output = parseAllLogicExpressions($input, $messages); // 👉 "2 + 1"
eval("echo $output;"); // 👉 "3"

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-06-17