array_key_exists()
The PHP array_key_exists() function is used to check whether the given key name or index exists in the array, and returns TRUE if it exists, otherwise returns FALSE.
grammar:
bool array_key_exists( mixed key, array search ) parameter key is the given key name or index, and can be any value that can be used as an array index.
The array_key_exists() function can also be used for objects.
example:
<?php $arr_a = array('id' => 1, 'name' => "admin"); if(array_key_exists('name', $arr_a)){ echo 'Key name name exists in the array $arr_a'; } else { echo 'Key name name does not exist in the array $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 with a value of null. To check whether the array element is null, use isset().
The above implementation method of checking whether the key name or index exists in an array is the entire content shared by the editor. I hope it can give you a reference and I hope you can support me more.