isset vs empty vs is_null

后端 未结 14 2167
野的像风
野的像风 2020-11-29 08:34

I\'m trying to write a script that when a user uploads a file and does not enter a name an error is returned. I\'ve tried using is_null, empty, and isset and they all do not

14条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 08:46

    isset()

    From PHP manual – isset():

    isset — Determine if a variable is set and is not NULL

    In other words, it returns true only when the variable is not null.

    empty()

    From PHP Manual – empty():

    empty — Determine whether a variable is empty

    In other words, it will return true if the variable is an empty string, false, array(), NULL, “0?, 0, and an unset variable.

    is_null()

    From PHP Manual – is_null():

    is_null — Finds whether a variable is NULL

    In other words, it returns true only when the variable is null. is_null() is opposite of isset(), except for one difference that isset() can be applied to unknown variables, but is_null() only to declared variables.

提交回复
热议问题