Posted By

canarymason on 08/31/09


Tagged

wildcard inarray


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

umang_nine


find needle w/ wildcard in an array


 / Published in: PHP
 

  1. /**
  2.  * Takes a needle and haystack (just like in_array()) and does a wildcard search on it's values.
  3.  *
  4.  * @param string $string Needle to find
  5.  * @param array $array Haystack to look through
  6.  * @result array Returns the elements that the $string was found in
  7.  */
  8. function wildcard_in_array ($string, $array = array ())
  9. {
  10. foreach ($array as $key => $value) {
  11. unset ($array[$key]);
  12. if (strpos($value, $string) !== false) {
  13. $array[$key] = $value;
  14. }
  15. }
  16. return $array;
  17. }

Report this snippet  

You need to login to post a comment.