
Variables that contain the PHP NULL value also evaluate toįalse.

Empty arrays evaluate to false and so do variables that are You can test anything that evaluates to true or false in an if Some people say just do if($var), if($myArray), or if($myArray) to determine emptiness. isset()is a much stricter test of emptiness (in the sense of your question) than empty(). None of mine do, so I use isset() to check if a $_POST key has no value associated with it (and that is not NULL). I have never known a form that submitted the PHP NULL value. In short, the most accurate check can be accomplished best with isset(), as some input controls do not even register with $_POST when they are not selected or checked. Second, it checks to make sure that value is not equal to the PHP NULL value. First it checks to see if a variable or array index/key has a value associated with it. The isset()language construct does two things. It can only operate on variables and array elements (via the index/key): isset($var) and isset($_POST). Isset() (a language construct) cannot operate on entire arrays, as in isset($myArray). A good use of empty() is to check if an entire array is empty (has no elements). The problem here is that empty() might be too broad to be used consistently (the same way, for the same reason, on different input control submissions to $_POST or $_GET).

If none of these values are valid for your input control, then empty() would work. $var (a variable declared, but without a value) Variable is considered empty if it does not exist or if its value " determines whether a variable is considered to be empty. Depends on what is allowed as valid input. Translation: Check to see if an array key/index has a value associated with it.Īnswer: Depends on your emphasis on security. Question: Check whether a $_POST value is empty.
