Checks whether a value is a string of zero length. Returns true only if the value is a string and its multibyte length is 0; any non-string value (null, int, array, etc.) returns false.
/**
* @param mixed $value
* @return bool
*/
Strings\isBlank($value): boolThis can be used to create a simple closure which can be used as a regular function.
// isBlank is called directly with the value under test — it is not a partially applied constructor like the rest of the Strings namespace.
var_dump(Strings\isBlank('')); // true
var_dump(Strings\isBlank('foo')); // false
// Only a zero-length string is considered blank. Any non-string value returns false.
var_dump(Strings\isBlank(null)); // false
var_dump(Strings\isBlank(0)); // false
var_dump(Strings\isBlank([])); // false
// A string of whitespace is NOT blank — trim the input first if you need that behaviour.
var_dump(Strings\isBlank(' ')); // false
var_dump(Strings\isBlank(Strings\trim(' ')(' '))); // trueIf you are not planning on reusing the Closure created, you can just call it inline with a higher order function as its callable.
// Pass the fully qualified name as a string callable to any higher order function.
$values = ['', 'foo', '', 'bar', ''];
$blanks = array_filter($values, 'PinkCrab\FunctionConstructors\Strings\isBlank');
print_r($blanks); // ['', '', '']
// Or use it as a negated predicate to strip blanks out.
$nonBlanks = array_filter($values, fn($v) => ! Strings\isBlank($v));
print_r($nonBlanks); // ['foo', 'bar']