Check if a variable is empty

前端 未结 4 1562
南旧
南旧 2020-12-11 13:10

I have some user-submitted variables that I want to display in a different part of my site like this:

Term:
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-11 13:42

    If isset() does not work, try empty() instead:

     
        
    Term:
    ID, $key, true); ?>

    isset() will deliver TRUE if the value is set and has a value different from NULL.

    empty() instead will deliver TRUE (hence !empty() results in FALSE) for:

    • "" (an empty string)
    • 0 (0 as an integer)
    • "0" (0 as a string)
    • NULL
    • FALSE
    • array() (an empty array)
    • var $var; (a variable declared, but without a value in a class)

    I assume your $key is set but with an empty string. Thus, empty() is the way to go here.

提交回复
热议问题