Skip to content

Repository files navigation

Title

This simple library exposes a single function - OneToMany\IsEmpty\is_empty() - to determine if a null, bool, array, or string value is truly empty.

Installation

composer require 1tomany/is-empty

is_empty() Overview

The is_empty() method has the following signature:

function is_empty(mixed $value, bool $trim = true): bool;
  • $value: The value being tested. Only values of type null, bool, array, and string are tested. Values of ALL other types will return false.
  • $trim: If the value being tested is a string, this function will use either the mb_trim() or trim() function to strip whitespace from the value first.

Truth Table

$value $trim is_empty()
null N/A true
false N/A true
true N/A false
'' true true
' ' true true
' ' false false
"\u{205F}" true true
"\u{205F}" false false
" 🐘 " true false
" 🐘 " false false
0 N/A false
1 N/A false
-1 N/A false
[] N/A true
[1] N/A false
\DateTime N/A false

About

A very simple library to determine if a variable is `null`, `false`, an empty array, or an empty string

Resources

Stars

Watchers

Forks

Releases

Contributors

Languages