How to check if $_GET is empty?

2019-01-07 10:19发布

How to check if $_GET is empty?

标签: php get
8条回答
甜甜的少女心
2楼-- · 2019-01-07 11:05
if (!$_GET) echo "empty";

why do you need such a checking?

lol
you guys too direct-minded.
don't take as offense but sometimes not-minded at all
$_GET is very special variable, not like others.
it is supposed to be always set. no need to treat it as other variables. when $_GET is not set and it's expected - it is emergency case and that's what "Undefined variable" notice invented for

查看更多
相关推荐>>
3楼-- · 2019-01-07 11:06

You said it yourself, check that it's empty:

if (empty($_GET)) {
    // no data passed by get
}

See, PHP is so straightforward. You may simply write, what you think ;)

This method is quite secure. !$_GET could give you an undefined variable E_NOTICE if $_GET was unset (not probable, but possible).

查看更多
登录 后发表回答