I understand that if $var = array()
, $var
will return true because even though the array is empty, it's still a set variable.
But $_GET
and $_POST
are not just arrays, they are arrays generated by PHP.
Why does PHP even set these variables if there's nothing to put in them? Is there something logical behind this that I'm missing?
therefore, $_GET is always available. This is the decision of the language developers.
http://www.php.net/manual/en/language.variables.superglobals.php
You should check wether they are empty or not with the empty()
function or check the amount of elements with the count()
function.
The arrays are always set, the question is: do they contain elements?
$_GET
and $_POST
both are super global variables, so these already set
as Array
, so you should used there empty()
method instead of isset()
if(empty($_GET)){
...
...
}