Possible Duplicate:
Check if $_POST exists
I'm trying to run something if and only if a $_POST var is populated.
Can I do if(empty($_POST[...])) { ... }
? Or should I go about this another way?
Possible Duplicate:
Check if $_POST exists
I'm trying to run something if and only if a $_POST var is populated.
Can I do if(empty($_POST[...])) { ... }
? Or should I go about this another way?
I'd do if(isset($_POST['key'])) { ... }
No, empty() is not the right way of doing it. You have to use isset().
Why? Because many things are considered empty which you probably don't want to miss!
The following things are considered to be empty:
"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
var $var; (a variable declared, but without a value in a class)