check if variable empty

前端 未结 12 1342
旧时难觅i
旧时难觅i 2020-11-27 14:00
if ($user_id == NULL || $user_name == NULL || $user_logged == NULL) {
    $user_id = \'-1\';
    $user_name = NULL;
    $user_logged = NULL;
}
if ($user_admin == NUL         


        
12条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 14:09

    If you want to test whether a variable is really NULL, use the identity operator:

    $user_id === NULL  // FALSE == NULL is true, FALSE === NULL is false
    is_null($user_id)
    

    If you want to check whether a variable is not set:

    !isset($user_id)
    

    Or if the variable is not empty, an empty string, zero, ..:

    empty($user_id)
    

    If you want to test whether a variable is not an empty string, ! will also be sufficient:

    !$user_id
    

提交回复
热议问题