To make a function which acts exactly like the empty() function in PHP, you'll have to go a bit further, as stated in the PHP documentation:
quote:
Source: http://www.php.net/manual/en/function.empty.php
The following things are considered to be empty:
- "" (an empty string)
- 0 (0 as an integer)
- "0" (0 as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var; (a variable declared, but without a value in a class)
Depending on what you want to do, you can choose which "kind of emptiness" you want to check:
- If it's a number, boolean, undefined or NULL variable, you can simply use if(!variable)
- If it's a string, you can compare it to an empty string with if(variable === "")
- If it's an array, you can check if it's empty with if(variable.length === 0)
- etc...