note 115941 added to function.array-search
| From: | podarokua at gmail dot com | Date: | Fri, 17 Oct 2014 04:45:06 +0000 |
| Subject: | note 115941 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-200668@lists.php.net to get a copy of this message | ||
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;
}
----
Server IP: 72.52.91.14
Probable Submitter: 62.205.141.199
----
Manual Page -- http://php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/115941
Del: integrated -- https://master.php.net/note/delete/115941/integrated
Del: useless -- https://master.php.net/note/delete/115941/useless
Del: bad code -- https://master.php.net/note/delete/115941/bad+code
Del: spam -- https://master.php.net/note/delete/115941/spam
Del: non-english -- https://master.php.net/note/delete/115941/non-english
Del: in docs -- https://master.php.net/note/delete/115941/in+docs
Del: other reasons-- https://master.php.net/note/delete/115941
Reject -- https://master.php.net/note/reject/115941
Search -- https://master.php.net/manage/user-notes.php