2016-03-02 34 views
-1

if (isset($_GET['user_name']) && !empty($_GET['user_name']))PHP中'isset'的用法是什麼?

在上面的代碼有什麼用零件 - (isset($_GET['user_name'])

+1

http://php.net/manual/en/function.isset.php –

+0

檢查值設置或不 – Nehal

+1

讀[isset](http://php.net/manual/en/function.isset.php)。 – Saty

回答

2

isset將檢查$_GET['user_name']設定,並沒有NULL。但如果您使用!empty($_GET['user_name']),則不需要isset(),因爲empty()會照顧它。

只有if (!empty($_GET['user_name']))將檢查是否設置了$_GET['user_name']並且它包含一個值。

注:empty()將返回true爲 -

  • 「」(空字符串)
  • 0(0作爲整數)
  • 0.0(0爲float)
  • 「0」(0作爲字符串)
  • NULL
  • FALSE
  • array()(一個空數組)
  • $ var; (變量聲明,但沒有一個值)

empty() & isset()