PHP 裡面有幾個判斷變數值的函式 empty()、isset()、is_null()

來記錄一下差別和他們回傳的值~


  1. isset()

    issetDetermine if a variable is set and is not NULL

    判斷變數是否有被指定值並且不為null,包括宣告變數但未指派值。

  2. empty()

    emptyDetermine whether a variable is empty

    判斷變數是否為空,以下情況即為空

    1. “”           (空字串)
    2. 0            (整數 0)
    3. 0.0        (浮點數 0.0)
    4. “0”        (“0” string)
    5. null
    6. false
    7. empty array
    8. $var      (宣告變數但不指派值)
  3. is_null()

    isnull — Finds whether the given variable is NULL.

    判斷變數是否為null

參考資料:

http://php.net/manual/en

Leave a Reply