php检查数组下标可否存在
发布时间:09/01 来源:未知 浏览:
关键词:
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检查数组下标可否存在的具体内容,更多请关注百分百源码网其它相关文章!