Getting confused with empty, isset, !empty, !isset

后端 未结 6 413
感情败类
感情败类 2021-01-21 19:10

I have the following which doesn\'t work properly as $_GET[\'category\'] can also equal 0.

if ( empty( $_GET[\'category\'] ) ){
    // do something
         


        
6条回答
  •  滥情空心
    2021-01-21 19:56

    if (!isset($_GET['category']))
    {
        1. Do something if $_GET['category'] does not exist at all
    }
    elseif ($_GET['category'] == 0)
    {
        2. Do something if $_GET['category'] == 0
    }
    elseif (isset($_GET['category']) && ($_GET['category'] != 0)
    {
        3. Do something if $_GET['category'] == something other than "does not exist" and 0.
    }
    

    My brackets might be slightly out somewhere but hopefully that should help you out.

提交回复
热议问题