Checking if a $_COOKIE value is empty or not

后端 未结 6 1935
盖世英雄少女心
盖世英雄少女心 2021-01-15 12:27

I assign a cookie to a variable:

$user_cookie = $_COOKIE[\"user\"];

How can I check if the $user_cookie received some value or

6条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-15 13:08

    These are the things empty will return true for:

    • "" (empty string)
    • 0 (0 as an integer)
    • 0.0 (0 as float)
    • "0" (0 as string)
    • NULL
    • FALSE
    • array() (an empty array)
    • var $var; (a declared variable not in a class)

    Taken straight from the php manual

    So to answer your question, yes, empty() will be a perfectly acceptable function, and in this instance I'd prefer it over isset()

提交回复
热议问题