If you want to test if the request was made using a POST request, then
checking $_SERVER['request_method'] is the way to go.
If you want to find out if an array is empty, there are some differences:
Empty will check if a variable is "empty". PHP considers the following values 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)
Empty is a language construct, which means you can't use it as a callback, so the following will fail:
$var = array(); call_user_func('empty', $var);
It also only checks variables, so the following will fail with a fatal too:
if (empty(array()) { // do something }
It is also faster than count, but this shouldn't make you consider it over the others.
Count is a "normal" function, it will first cast the parameter to an array, and check if it is empty. Personally I would use this to check empty arrays.
- if ($value) { // do something }
This differs a little from count, because $value here will be cast to a boolean, and because empty arrays cast to false, it will achieve the same result as count.
There is a very big gotcha involved because of casting:
$var = ''; // empty string
var_dump(empty($var)); // returns true
var_dump(count($var)); // returns false