note 115941 deleted from function.array-search by cmb
| From: | cmb@php.net | Date: | Sun, 01 Sep 2019 08:00:10 +0000 |
| Subject: | note 115941 deleted from function.array-search by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212081@lists.php.net to get a copy of this message | ||
Note Submitter: podarokua at gmail dot com
----
Here is a method for getting all keys, containing searched value, recursively
/**
* Recursive array search.
*
* See http://php.net/manual/en/function.array-search.php#91365
*
* @param $needle
* The searched value.
* @param $haystack
* The array.
*
* @return bool|int|string
* Array of keys, containing values or FALSE if not found.
*/
private function ras($needle, $haystack) {
$keys = array();
foreach ($haystack as $key => $value) {
if ($needle === $value OR (is_array($value) && $this->ras(
$needle,
$value
) !== FALSE)
) {
$keys[] = $key;
}
}
if (!empty($keys)) {
return $keys;
}
return FALSE;
}