【php数组函数序列】之array_key_exists()

简介:这是【php数组函数序列】之array_key_exists()的详细页面,介绍了和php,有关的知识、技巧、经验,和一些php源码等。

class='pingjiaF' frameborder='0' src='http://biancheng.dnbcw.info/pingjia.php?id=361889' scrolling='no'>

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!
来源:http://www.cnblogs.com/zhouisizhi/

爱J2EE关注Java迈克尔杰克逊视频站JSON在线工具

http://biancheng.dnbcw.info/php/361889.html pageNo:1
原文地址:https://www.cnblogs.com/ooooo/p/2235967.html