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

后端 未结 6 468
感情败类
感情败类 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:42

    Try this:

    if (!isset($_GET['category'])) { // if variable not specified
    }
    elseif ($_GET['category'] == 0) { // variable is specified and zero
    }
    else { // variable is specified and not zero
    }
    

提交回复
热议问题