note 118744 added to function.in-array
| From: | tjamadeira at gmail dot com | Date: | Fri, 29 Jan 2016 19:17:32 +0000 |
| Subject: | note 118744 added to function.in-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204799@lists.php.net to get a copy of this message | ||
This function is for search a needle in a multidimensional haystack:
<?php
/**
* A special function for search in a multidimensional array a needle
*
* @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){
foreach($haystack as $item){
if(is_array($item)){
if(in_array_r($needle, $item, $strict)){
return true;
}
}else{
if(($strict ? $needle === $item : $needle == $item)){
return true;
}
}
}
return false;
}
?>
----
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/118744
Del: integrated -- https://master.php.net/note/delete/118744/integrated
Del: useless -- https://master.php.net/note/delete/118744/useless
Del: bad code -- https://master.php.net/note/delete/118744/bad+code
Del: spam -- https://master.php.net/note/delete/118744/spam
Del: non-english -- https://master.php.net/note/delete/118744/non-english
Del: in docs -- https://master.php.net/note/delete/118744/in+docs
Del: other reasons-- https://master.php.net/note/delete/118744
Reject -- https://master.php.net/note/reject/118744
Search -- https://master.php.net/manage/user-notes.php