PHPackages                             hoanglongtrinh/logic-expression - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. hoanglongtrinh/logic-expression

ActiveLibrary

hoanglongtrinh/logic-expression
===============================

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

v1.7(10mo ago)012MITPHPPHP &gt;=7.2

Since Jun 17Pushed 10mo agoCompare

[ Source](https://github.com/HoangLongTrinh/logic-expression)[ Packagist](https://packagist.org/packages/hoanglongtrinh/logic-expression)[ RSS](/packages/hoanglongtrinh-logic-expression/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (9)Used By (0)

Logic Expression
================

[](#logic-expression)

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

Supported functions
-------------------

[](#supported-functions)

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

Installation
------------

[](#installation)

```
composer require hoanglongtrinh/logic-expression
```

use
---

[](#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"

```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance53

Moderate activity, may be stable

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

8

Last Release

327d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/acb2365c42fcec01b418fc871ea58ba24ee69d1e6e48d781e6dde9d5dafea43b?d=identicon)[HoangLongTrinh](/maintainers/HoangLongTrinh)

---

Top Contributors

[![HoangLongTrinh](https://avatars.githubusercontent.com/u/15134903?v=4)](https://github.com/HoangLongTrinh "HoangLongTrinh (1 commits)")

### Embed Badge

![Health badge](/badges/hoanglongtrinh-logic-expression/health.svg)

```
[![Health](https://phpackages.com/badges/hoanglongtrinh-logic-expression/health.svg)](https://phpackages.com/packages/hoanglongtrinh-logic-expression)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
