note 117845 deleted from function.array-key-exists by crell
| From: | crell@php.net | Date: | Wed, 29 Jun 2022 20:39:12 +0000 |
| Subject: | note 117845 deleted from function.array-key-exists by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218747@lists.php.net to get a copy of this message | ||
Note Submitter: p dot allgeier at web dot de
----
If u want to check if a key exists either in the array or in any subarray try the following:
<?php
function requireKey($needle, array $array)
{
foreach ($array as $key => $value) {
if ($key === $needle) return $value;
if (is_array($value)) {
if ($x = $this->requireKey($key, $value)) return $x;
}
}
return false;
}
?>
(( return $value for recursive array search, return true for recursive array key exists ))