ephpicman/boolean-utility 问题修复 & 功能扩展

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

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

ephpicman/boolean-utility

最新稳定版本:v1.0.0

Composer 安装命令:

composer require ephpicman/boolean-utility

包简介

A comprehensive Boolean utility for PHP, supporting logical operations, counting, and majority evaluation.

README 文档

README

License: MIT

A comprehensive PHP utility for working with booleans and boolean-like values.
Designed to simplify boolean checks, logical operations, counting, and majority logic in PHP projects.

Table of Contents

Installation

Use Composer to install:

composer require ephpicman/boolean-utility

Autoloading is PSR-4 compliant:

use EphpicMan\BooleanUtility\BooleanUtility;

Usage

The BooleanUtility class provides tools for:

  • Boolean type checks
  • Conversion of various values to boolean
  • Logical operations (AND, OR, XOR, etc.)
  • Counting true/false values
  • Determining majority
  • Aliases and toggle operations

Class: BooleanUtility

Checking Methods

MethodDescription
is(mixed $variable): boolChecks if a variable is strictly boolean.
isNot(mixed $variable): boolChecks if a variable is not boolean.
isTruthy(mixed $variable): boolChecks if a value evaluates to true.
isFalsy(mixed $variable): boolChecks if a value evaluates to false.

Conversion

MethodDescription
toBoolean(mixed ...$variables): bool | arrayConverts values to boolean. Strings matching true values, numbers, booleans, and arrays are all supported.

Logical Operations

MethodDescription
and(mixed ...$variables): boolLogical AND across multiple values.
nand(mixed ...$variables): boolLogical NAND across multiple values.
or(mixed ...$variables): boolLogical OR across multiple values.
nor(mixed ...$variables): boolLogical NOR across multiple values.
xor(mixed ...$variables): boolLogical XOR across multiple values.
xnor(mixed ...$variables): boolLogical XNOR across multiple values.
not(bool ...$variables): bool | arrayLogical NOT / toggle boolean values.

Counting Methods

MethodDescription
countTrue(mixed ...$variables): intCounts how many inputs are true.
countFalse(mixed ...$variables): intCounts how many inputs are false.

Majority Methods

MethodDescription
majorityTrue(mixed ...$variables): boolReturns true if the majority of inputs are true.
majorityFalse(mixed ...$variables): boolReturns true if the majority of inputs are false.
majority(mixed ...$variables): bool | nullReturns the majority value (true or false). Returns null if tie.

Aliases

MethodDescription
allTrue(...$vars): boolAlias for and().
allFalse(...$vars): boolAlias for nor().
xand(...$vars): boolAlias for and().
xnand(...$vars): boolAlias for nand().
anyTrue(...$vars): boolAlias for or().
anyFalse(...$vars): boolAlias for nor().

Toggle

MethodDescription
toggle(bool ...$variables): bool | arrayAlias for not().

Examples

use EphpicMan\BooleanUtility\BooleanUtility;

// Simple boolean checks
BooleanUtility::is(true);       // true
BooleanUtility::isNot('test');  // true

// Convert mixed values
BooleanUtility::toBoolean('yes');   // true
BooleanUtility::toBoolean(0);       // false
BooleanUtility::toBoolean([1, 'no']); // [true, false]

// Logical operations
BooleanUtility::and(true, 'yes', 1);  // true
BooleanUtility::or(false, 0, 'ok');   // true
BooleanUtility::xor(true, true, false); // false

// Counting
BooleanUtility::countTrue(true, false, 'yes');  // 2
BooleanUtility::countFalse(true, false, 'yes'); // 1

// Majority
BooleanUtility::majorityTrue(true, false, 'yes'); // true
BooleanUtility::majority(false, false, true, true); // null (tie)

// Toggle
BooleanUtility::toggle(true, false); // [false, true]

License

This package is released under the MIT License. Anyone may use, modify, or distribute it personally or commercially.

Git Repository

https://git.ephpic.org/ephpicman/boolean-utility

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-12-04