How to check if $_GET is empty?

后端 未结 8 858
太阳男子
太阳男子 2020-11-28 07:42

How to check if $_GET is empty?

相关标签:
8条回答
  • 2020-11-28 08:18

    Just to provide some variation here: You could check for

    if ($_SERVER["QUERY_STRING"] == null)
    

    it is completely identical to testing $_GET.

    0 讨论(0)
  • 2020-11-28 08:19

    I would use the following if statement because it is easier to read (and modify in the future)

    
    if(!isset($_GET) || !is_array($_GET) || count($_GET)==0) {
       // empty, let's make sure it's an empty array for further reference
       $_GET=array();
       // or unset it 
       // or set it to null
       // etc...
    }
    
    0 讨论(0)
  • 2020-11-28 08:26
    <?php
    if (!isset($_GET) || empty($_GET))
    {
        // do stuff here
    }
    
    0 讨论(0)
  • 2020-11-28 08:28

    i guess the simplest way which doesn't require any operators is

    if($_GET){
    //do something if $_GET is set 
    } 
    if(!$_GET){
    //do something if $_GET is NOT set 
    } 
    
    0 讨论(0)
  • 2020-11-28 08:32
    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

    0 讨论(0)
  • 2020-11-28 08:33

    Easy.

    if (empty($_GET)) {
        // $_GET is empty
    }
    
    0 讨论(0)
提交回复
热议问题