In PHP we often have more than one way of doing the same operation. A basic example is in checking for the existence of a given index in array
: we can use array_keys_exists
.
Example:
$arr = ['a' => 1, 'b' => 2];
var_dump(isset($arr['a'])); // bool(true)
var_dump(array_key_exists($arr, 'a')); //bool(true)
Since the results are the same, I would like to know:
-
Is there any difference between
isset
andarray_keys_ exists
when checking for index existence? -
Is there a difference in performance?
-
When should I use one or the other?