note 20619 deleted from function.empty by alindeman
| From: | alindeman@php.net | Date: | Wed, 10 Apr 2002 12:23:57 +0000 |
| Subject: | note 20619 deleted from function.empty by alindeman | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-29054@lists.php.net to get a copy of this message | ||
Perhaps the good people at php would considering adding the following function to the core of php.
It would be super helpful when working in programs. Basically, it determines if a variable actually
has contents with an optional setting that considers whitespace insufficient for considering a
variable to have contents.
/**
* Determine if the value of the variable contains no value.
*
* This function represents empty() in its true form. If the variable
* contains absolutely no data, or is just an empty array, then the
* boolean value 'true' is returned. If it has a value of 0 or contains
* only spaces or endlines (and the strict is not set) then it returns
* false. This is unlike the php function empty() which just returns
* if the variable would evaluate as true or false.
*
* @param mixed $in_var variable to be evaluated
* @param bool $in_strict (optional) whitespace counts
*
* @access public
* @return bool whether the variable has contents or not
*/
if (!function_exists('isempty')) {
function isempty($in_var, $in_strict = true)
{
$var = $in_strict ? $in_var : trim($in_var);
return (!isset($var) || $var === '' || (is_array($var) && empty($var))) ?
true : false;
}
}