"Cat");if (array_key_exists("a",$a)){echo "Key exists!";}else{echo "Key does not exist!";}?>输出:Key exists!例2:">
当前位置:Gxlcms > PHP教程 > php数组函数array_key_exists()查找数组键名是否存在

php数组函数array_key_exists()查找数组键名是否存在

时间:2021-07-01 10:21:17 帮助过:26人阅读

  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!

人气教程排行