note 118743 deleted from function.in-array by cmb
| From: | cmb@php.net | Date: | Mon, 21 Jan 2019 14:20:18 +0000 |
| Subject: | note 118743 deleted from function.in-array by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-210087@lists.php.net to get a copy of this message | ||
Note Submitter: tjamadeira at gmail dot com
----
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);
}
}
?>