note 67126 deleted from function.empty by danbrown
| From: | danbrown@php.net | Date: | Fri, 28 Nov 2008 22:08:09 +0000 |
| Subject: | note 67126 deleted from function.empty by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147305@lists.php.net to get a copy of this message | ||
Note Submitter: Karl Jung
----
This function I did, works like empty(), but doesn't consider zero (0) as empty.
Also, considers as empty, a string containing only blank spaces, or "\n", "\t",
etc.
function my_empty($val)
{
$result = false;
if (empty($val))
$result = true;
if (!$result && (trim($val) == ""))
$result = true;
if ($result && is_numeric($val) && $val == 0)
$result = false;
return $result;
}
Values considered as EMPTY:
$val = "";
$val = " ";
$val = " \t \n ";
$val = array();
$val = false;
$val = null;
Values considered NOT EMPTY:
$val = "0";
$val = intval(0);
$val = floatval(0);