aelora/truthy

Add a simple isTruthy and isFalsy function to see if things are true-like or false-like

Fund package maintenance!
RyanNutt

1.0.1 2022-07-21 13:20 UTC

This package is auto-updated.

Last update: 2025-02-21 19:12:32 UTC


README

isTruthy / isFalsy

Latest Version on Packagist Total Downloads

Simple PHP package to add an isTruthy and isFalsy function.

And yes, I know this is simple to almost a silly level. But it's something that I found myself adding to a bunch of different PHP projects so it seemed like a perfect bit of code to build into a package.

Installation

Install using composer

composer require aelora/truthy

There are no settings.

Usage

Once loaded, there will be an isTruthy and isFalsy function in the global namespace.

The following values are considered falsy

  • false
  • null
  • empty string
  • 0
  • 0.0
  • empty array
  • empty object
  • strings "no", "n", "false", "f", "off", "null", "0", "0.0"

Everything else is considered truthy.

if (isTruthy($value)) {
    // Do something
} 
if (isFalsy($value)) {
    // Do something
}

Tests

composer test