This article is an example of a method for specifying a key in the array of PHP judgments. Share to everyone for your reference. The specific analysis is as follows:
PHP has two functions to determine whether the array contains the specified keys, respectively, Array_key_exists and Isset
The array_key_exists syntax is as follows
Array_key_exists ($key, $array)
If the key exists to return true isset function syntax is as follows
If the key exists to return true
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? 1 is
' 1′defined?
Is ' two ' defined? 1 is
' 2′defined?
I hope this article will help you with your PHP program design.