首页 > 代码库 > PHP key_exists

PHP key_exists

此函数同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 }

例子二:

 

PHP key_exists