找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索本站精品资源

首页 教程频道 php教程 查看内容

php检查数组下标是否存在

作者:模板之家 2019-10-11 17:24 10382人关注

php检查数组下标是否存在的方法是:使用array_key_exists()函数检查某个数组中是否存在指定的键名,如果键名存在则返回true,如果键名不存在则返回false。

PHP检查数组下标是否存在的方法

array_key_exists()函数

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

语法:

array_key_exists(key,array)

参数描述:

key 必需。规定键名。

array 必需。规定输入的数组。

实例:

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

输出:

Key exists!

实例:

<?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!

实例:

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

输出:

Key exists!

推荐教程:PHP视频教程

以上就是php检查数组下标是否存在的详细内容,更多请关注模板之家(www.mb5.com.cn)其它相关文章!


路过

雷人

握手

鲜花

鸡蛋
来自: [db:来源]

全部回复(0)

发表评论