note 118743 added to function.in-array
| From: | tjamadeira at gmail dot com | Date: | Fri, 29 Jan 2016 17:20:02 +0000 |
| Subject: | note 118743 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204798@lists.php.net to get a copy of this message | ||
A recursive function for a search in a multidimensional array using the in_array PHP function.
<?php
/**
* A special function for search in a multidimensional array a needle
*
* This function uses many times the in_array PHP function
* to search a needle in a multidimensional haystack.
*
* @param mixed needle The searched variable
* @param array haystack The array where search
* @param bool strict It is or it isn't a strict search?
*
* @return bool
**/
function in_array_r($needle, $haystack, $strict = false){
if(in_array(array(), $haystack, $strict)){
foreach($haystack as $item){
if(is_array($item)){
return in_array_r($needle, $item, $strict);
}else {
return in_array($needle, $haystack, $strict);
}
}
}else {
return in_array($needle, $haystack, $strict);
}
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 2001:8a0:6a58:ee01:224:8cff:fe7b:db32
----
Manual Page -- http://php.net/manual/en/function.in-array.php
Edit -- https://master.php.net/note/edit/118743
Del: integrated -- https://master.php.net/note/delete/118743/integrated
Del: useless -- https://master.php.net/note/delete/118743/useless
Del: bad code -- https://master.php.net/note/delete/118743/bad+code
Del: spam -- https://master.php.net/note/delete/118743/spam
Del: non-english -- https://master.php.net/note/delete/118743/non-english
Del: in docs -- https://master.php.net/note/delete/118743/in+docs
Del: other reasons-- https://master.php.net/note/delete/118743
Reject -- https://master.php.net/note/reject/118743
Search -- https://master.php.net/manage/user-notes.php