gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

php怎么样使用array_key_exists() 函数实例详解

来源:http://erdangjiade.com/topic/2520.html 你好,世界。 2017-09-25 22:42浏览(35)

array_key_exists() 定义和用法

array_key_exists() 函数判断某个数组中是否存在指定的 key,如果该 key 存在,则返回 true,否则返回 false。

语法
array_key_exists(key,array)
参数 描述
key 必需。规定键名。
array 必需。规定输入的数组。

例子 1

<?php 
$a=array("a"=>"Dog","b"=>"Cat"); 
if (array_key_exists("a",$a)) 
{ 
echo
 "Key exists!"; 
} 
else
 
{ 
echo "Key does not exist!"; 
} 
?>


输出:

Key exists!
例子 2

<?php 
$a=array("a"=>"Dog","b"=>"Cat"); 
if (array_key_exists("c",$a)) 
{ 
echo "Key exists!"; 
} 
else 
{ 
echo "Key does not exist!"; 
} 
?>


输出:

Key does not exist!
例子 2

<?php 
$a=array("Dog",Cat"); 
if (array_key_exists(0,$a)) 
{ 
echo "Key exists!"; 
} 
else 
{ 
echo "Key does not exist!"; 
} 
?>


输出:

Key exists!

以上就是php如何使用array_key_exists() 函数实例详解的详细内容,更多请关注二当家的素材网其它相关文章!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2