当前位置:Gxlcms >
PHP教程 >
php数组函数array_key_exists()查找数组键名是否存在
php数组函数array_key_exists()查找数组键名是否存在
时间:2021-07-01 10:21:17
帮助过:26人阅读
- $a=array("a"=>"Dog","b"=>"Cat");
- if (array_key_exists("a",$a))
- {
- echo "Key exists!";
- }
- else
- {
- echo "Key does not exist!";
- }
- ?>
输出:
Key exists!
例2:
- $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!
例3:
- $a=array("Dog",Cat");
- if (array_key_exists(0,$a))
- {
- echo "Key exists!";
- }
- else
- {
- echo "Key does not exist!";
- }
- ?>
输出:
Key exists! |