note 85749 deleted from function.in-array by cmb

From: Date: Sun, 15 Sep 2019 13:04:29 +0000
Subject: note 85749 deleted from function.in-array by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-212192@lists.php.net to get a copy of this message
Note Submitter: james dot randell at hotmail dot co dot uk ---- Small method i built for my Array module, after looking through the manual I wanted a small compact way of making a wildcard search through an arrays values, and returning only those that it found. <?php /** * Takes a needle and haystack (just like in_array()) and does a wildcard search on it's values. * * @param string $string Needle to find * @param array $array Haystack to look through * @result array Returns the elements that the $string was found in */ function find ($string, $array = array ()) { foreach ($array as $key => $value) { unset ($array[$key]); if (strpos($value, $string) !== false) { $array[$key] = $value; } } return $array; } ?>

« previous php.notes (#212192) next »