Home > php教程 > php手册 > body text

PHP array_key_exists检查键名或索引是否存在于数组中的实现方法,arraykeyexists

WBOY
Release: 2016-07-06 14:24:45
Original
973 people have browsed it

PHP array_key_exists检查键名或索引是否存在于数组中的实现方法,arraykeyexists

array_key_exists()

PHP array_key_exists() 函数用于检查给定的键名或索引是否存在于数组中,如果存在则返回 TRUE ,否则返回 FALSE 。

语法:

bool array_key_exists( mixed key, array search )参数 key 是给定的键名或索引,可以是任何能作为数组索引的值。

array_key_exists() 函数也可用于对象。

例子:

<&#63;php
$arr_a = array('id' => 1, 'name' => "admin");
if(array_key_exists('name', $arr_a)){
  echo '键名 name 存在于数组 $arr_a 中';
} else {
  echo '键名 name 不存在于数组 $arr_a 中';
}
&#63;>
Copy after login

例子输出结果如下:

键名 name 存在于数组 $arr_a 中array_key_exists() 函数对于值为 null 的数组元素仍返回 TRUE。若要对数组元素是否为 null 做检查,请使用 isset()。

以上这篇PHP array_key_exists检查键名或索引是否存在于数组中的实现方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持帮客之家。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!