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:
<?php $arr_a = array('id' => 1, 'name' => "admin"); if(array_key_exists('name', $arr_a)){ echo '键名 name 存在于数组 $arr_a 中'; } else { echo '键名 name 不存在于数组 $arr_a 中'; } ?>
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.