Advertisement
petschko

function is_in_array with deep search

Jul 28th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Author: Peter Dragicevic [peter-91@hotmail.de]
  4.  * Authors-Website: http://petschko.org/
  5.  * Licence: http://creativecommons.org/licenses/by-sa/4.0/
  6.  * Date: 28.07.2015
  7.  * Time: 09:36
  8.  */
  9.  
  10. /**
  11.  * @param mixed $subject - needle
  12.  * @param array $array - haystack
  13.  * @param bool $deep_search - search subarrays too
  14.  * @return bool - true if found
  15.  */
  16. function is_in_array($subject, $array, $deep_search = false) {
  17.     if(! $subject)
  18.         return false;
  19.  
  20.     foreach($array as $string) {
  21.         if(is_array($string) && $deep_search)
  22.             if(is_in_array($subject, $string, true))
  23.                 return true;
  24.         if($string == $subject)
  25.             return true;
  26.     }
  27.  
  28.     return false;
  29. }
  30.  
  31. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement