PHP array_key_exists implementation method to check whether the key name or index exists in the array, arraykeyexists_PHP tutorial

WBOY
Release: 2016-07-12 08:49:43
Original
865 people have browsed it

PHP array_key_exists implementation method to check whether the key name or index exists in the array, arraykeyexists

array_key_exists()

PHP array_key_exists() function is used to check whether the given key name or index exists in the array. If it exists, it returns TRUE, otherwise it returns FALSE.

Grammar:

bool array_key_exists(mixed key, array search) parameter key is the given key name or index, which can be any value that can be used as an array index.

The array_key_exists() function also works on objects.

Example:

<&#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

The example output results are as follows:

The key name name exists in the array $arr_a. The array_key_exists() function still returns TRUE for array elements whose value is null. To check whether an array element is null, use isset().

The above implementation method of PHP array_key_exists to check whether the key name or index exists in the array is all the content shared by the editor. I hope it can give you a reference, and I hope you will support Bangkejia more.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1136644.htmlTechArticlePHP array_key_exists implementation method to check whether the key name or index exists in the array, arraykeyexists array_key_exists() PHP array_key_exists() Function used to check a given key name or index...
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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template