首頁 >後端開發 >php教程 >php陣列函數array_key_exists() 尋找陣列鍵名是否存在

php陣列函數array_key_exists() 尋找陣列鍵名是否存在

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB原創
2016-07-25 09:04:501135瀏覽
  1. $a=array("a"=>"Dog","b"=>"Cat");
  2. if (array_key_exists("a",$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
复制代码

输出: Key exists!

例2:

  1. $a=array("a"=>"Dog","b"=>"Cat");
  2. if (array_key_exists("c",$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
复制代码

输出: Key does not exist!

例3:

  1. $a=array("Dog",Cat");
  2. if (array_key_exists(0,$a))
  3. {
  4. echo "Key exists!";
  5. }
  6. else
  7. {
  8. echo "Key does not exist!";
  9. }
  10. ?>
复制代码

输出: Key exists!



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn