首页 > 技术文章 > PHP key_exists

jingjingdidunhe 2017-06-17 00:16 原文

此函数同array_key_exsits().

1.函数的作用:判断一个数组是否含有某个键值

2.函数的参数:

  @param string  $key

  @param array $haystack

3.

例子一:

 1 <?php
 2 $arr = ['key' => null];
 3 
 4 echo "To check whether key exist?\n";
 5 echo "The result of the isset() function : " .( isset($arr['key']) ? 1 : 0 )."\n";
 6 echo "The result of the key_exists() function :" .key_exists('key',$arr) ."\n";
 7 echo "It's a big problem! The isset() function is faster than the key_exists() function.\n";
 8 echo "So you can use the snip code :\n";
 9 
10 if(isset($arr['key']) || key_exists('key',$arr)){
11     echo "'Key' is exist in arr array!\n";
12 }

例子二:

 

推荐阅读