This article describes how to use php to determine whether a specified key exists in an array. The example shows how to use array_key_exists and isset in php, which is very useful, for more information about how to use php to determine whether a specified key exists in an array, see the following example. Share it with you for your reference. The specific analysis is as follows:
Php has two functions to determine whether the array contains the specified keys: array_key_exists and isset.
The array_key_exists syntax is as follows:
Array_key_exists ($ key, $ array)
If the key exists, the true isset function syntax is returned as follows:
Isset ($ array [$ key])
Returns true if the key exists.
The demo code is as follows:
<? Php $ array = array ("Zero" => "PHP", "One" => "Perl", "Two" => "Java "); print ("Is 'one' defined? ". Array_key_exists (" One ", $ array)." \ n "); print (" Is '1' defined? ". Array_key_exists (" 1 ", $ array)." \ n "); print (" Is 'two' defined? ". Isset ($ array [" Two "])." \ n "); print (" Is '2' defined? ". Isset ($ array [2])." \ n ");?>
The returned results are as follows:
Is 'one' defined? 1Is '1' defined? Is 'two' defined? 1Is '2' defined?
I hope this article will help you with php programming.