note 61492 deleted from function.array-key-exists by bjori
| From: | bjori@php.net | Date: | Mon, 01 May 2006 22:30:57 +0000 |
| Subject: | note 61492 deleted from function.array-key-exists by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-110313@lists.php.net to get a copy of this message | ||
Note Submitter: kitchin
----
This function is partway between strict and not strict on type matching.
$x= array('that');
$test= array_key_exists(0, $x);
var_dump($test); // true
$x= array('that');
$test= array_key_exists('0', $x);
var_dump($test); // true... not strict!
$x= array('this'=>'that');
$test= array_key_exists(0, $x);
var_dump($test); // false... strict!
Here is a function for strict checking. It's not efficient for multiple lookups.
function array_key_exists_strict($key, $array) {
$keys= array_keys($array);
return in_array($key, $keys, true); // strict
}