新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
PHParray_key_exists():判斷數(shù)組的鍵名或索引是否存在
在 php 中,使用 array_key_exists() 函數(shù)可以判斷給定的鍵名或索引是否存在于數(shù)組中。因?yàn)樵谝粋€(gè)數(shù)組中鍵名是唯一的,所以不需要對(duì)其數(shù)據(jù)類型進(jìn)行判斷。

array_key_exists() 函數(shù)的語法格式如下:
array_key_exists($key, $array)
其中,$key 為要檢查的鍵名;$array 為一個(gè)數(shù)組,array_key_exists() 函數(shù)可以檢查數(shù)組 $array 中是否存在 $key 這個(gè)鍵名,存在時(shí)函數(shù)返回 TRUE,不存在時(shí)返回 FALSE。
提示:array_key_exists() 函數(shù)僅能判斷數(shù)組第一維的鍵名,不能判斷多維數(shù)組里嵌套的鍵名。
【示例】使用 array_key_exists() 函數(shù)檢查數(shù)組中是否存在指定鍵名。
'C語言中文網(wǎng)',
'url' =>'http://c.biancheng.net/php/',
'title' =>'PHP 教程',
array(
'id'=>'1234',
'article'=>'array_key_exists() 函數(shù)'
)
);
if(array_key_exists('url', $array)){
echo '鍵名“url”存在
';
}else{
echo '鍵名“url”不存在
';
}
if(array_key_exists('article', $array)){
echo '鍵名“article”存在
';
}else{
echo '鍵名“article”不存在
';
}
?>
運(yùn)行結(jié)果如下:
鍵名“url”存在
鍵名“article”不存在
分享文章:PHParray_key_exists():判斷數(shù)組的鍵名或索引是否存在
文章位置:http://fisionsoft.com.cn/article/cocsjpe.html


咨詢
建站咨詢
