note 20619 added to function.empty

From: Date: Wed, 10 Apr 2002 09:52:12 +0000
Subject: note 20619 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-29047@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; } } -- http://www.php.net/manual/en/function.empty.php http://master.php.net/manage/user-notes.php?action=edit+20619 http://master.php.net/manage/user-notes.php?action=delete+20619 http://master.php.net/manage/user-notes.php?action=reject+20619

« previous php.notes (#29047) next »