note 54332 deleted from function.in-array by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: alex at alexelectronics dot com 

----

A foreach would be simpler for a multi-dimensional array search (and probably faster, since you an use the value instead of the index).  Like this:

<?PHP
function in_multi_array($needle, $haystack) {
   $in_multi_array = false;
   if(in_array($needle, $haystack)) {
       $in_multi_array = true;
   } else {
       foreach $haystack as ($key => $val) {
           if(is_array($val)) {
               if(in_multi_array($needle, $val)) {
                   $in_multi_array = true;
                   break;
               }
           }
       }
   }
   return $in_multi_array;
}
?>

Using is_array($val) is probably faster than using is_array($haystack[$key])
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.