By John Koster
The blank
function is used to determine if the provided value contains a value that is not null
, or a non empty value. It can be useful to check arguments supplied to functions for values without having to check many different types specifically. A value is considered blank or empty if any of the following conditions are true:
- The value is
null
, - The value is a string and contains only whitespace or is of length
0
, - The value is not numeric,
- The value is not a
boolean
value, - The value is a
Countable
object and contains no items, - the PHP
empty
evaluates totrue
#Signature
The signature of the blank
function is:
1function blank(
2 $value
3);
#Example Use
The following example demonstrates the basic usage of the blank
function:
1// Set a value to null.
2$testValue = null;
3
4if (blank($testValue)) {
5 // Perform some action when the value is blank.
6} else {
7 // Perform a different action when the
8 // supplied value is not blank.
9}
∎