Why check both isset() and !empty()

后端 未结 10 2504
难免孤独
难免孤独 2020-11-21 23:48

Is there a difference between isset and !empty. If I do this double boolean check, is it correct this way or redundant? and is there a shorter way

10条回答
  •  被撕碎了的回忆
    2020-11-22 00:05

    • From the PHP Web site, referring to the empty() function:

    Returns FALSE if var has a non-empty and non-zero value.

    That’s a good thing to know. In other words, everything from NULL, to 0 to “” will return TRUE when using the empty() function.

    • Here is the description of what the isset() function returns:

    Returns TRUE if var exists; FALSE otherwise.

    In other words, only variables that don’t exist (or, variables with strictly NULL values) will return FALSE on the isset() function. All variables that have any type of value, whether it is 0, a blank text string, etc. will return TRUE.

提交回复
热议问题