How to check if $_GET is empty?

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

How to check if $_GET is empty?

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

    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).

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

    Here are 3 different methods to check this

    <?php
    //Method 1
    if(!empty($_GET))
    echo "exist";
    else
    echo "do not exist";
    //Method 2
    echo "<br>";
    if($_GET)
    echo "exist";
    else
    echo "do not exist";
    //Method 3
    if(count($_GET))
    echo "exist";
    else
    echo "do not exist";
    ?>
    
    0 讨论(0)
提交回复
热议问题