Home  >  Article  >  php教程  >  php-Arrays函数-array_key_exists-检查给定的键名或索引是否存在于数组中

php-Arrays函数-array_key_exists-检查给定的键名或索引是否存在于数组中

WBOY
WBOYOriginal
2016-06-13 10:49:31939browse

array_key_exists() 检查给定的键名或索引是否存在于数组中

【功能】
         该函数将返回一个布尔型值,
         如果指定的key存在于指定的数组中则返回true,否则返回false
         同时该函数也可以用于对象,即检查指定的key是否在于对象中
【使用范围】
         php4>4.1.0、php5.
【使用】
         bool array_key_exists(mixed key,array search)
         key/必需/键名
         search/必需/查找的数组
【示例】
[php]
$search_array = array('first'=>1,'second'=>4); 
if(array_key_exists('first',$search_array)){ 
        echo "The 'first' element is in the array"; 

/*
The 'first' element is in the array
*/ 

 

摘自 zuodefeng的笔记

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn