This simple library exposes a single function - OneToMany\IsEmpty\is_empty() - to determine if a null, bool, array, or string value is truly empty.
composer require 1tomany/is-empty
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 typenull,bool,array, andstringare tested. Values of ALL other types will returnfalse.$trim: If the value being tested is a string, this function will use either themb_trim()ortrim()function to strip whitespace from the value first.
$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 |