Comparison of PHP isset and array_key_exists
essence. PHP isset is a language structure, and array_key_exists is a function, which executes There is a difference in speed, and more importantly, in some cases, the results returned by the two are different. Many engineers hope to increase the performance of program execution and use isset to process array key queries. But not all situations are suitable to use isset to replace array_key_exists .
Basic syntax of PHP isset and array_key_exists
bool isset (array key to be checked); bool array_key_exists (key name $key to be queried, PHP array to be checked)
It can be known from the syntax that both of them are returning the Boolean value, that is, TRUE OR FALSE. The two seemingly similar usages are actually different.
PHP isset and array_key_exists return the difference
$NewArray = array('A' => null,'B' =>'');
if (isset($NewArray[A])) {
echo "Use isset to find the key name A in the array<br> ";
}
if (isset($NewArray[B])) {
echo "Use isset to find the key name B in the array<br>";
}
if (array_key_exists('A', $NewArray)) {
echo "Use array_key_exists to find The array contains the key name A<br>";
}
if (array_key_exists('B', $NewArray)) {
echo "Use array_key_exists to find the key name B in the array";
}
?>
in the array Use array_key_exists to find the key name A
in the array Use array_key_exists to find the key name B in the array
 
 
Post a Comment
0 Comments