note 77525 deleted from function.array-search by crell

From: Date: Thu, 31 Mar 2022 20:37:04 +0000
Subject: note 77525 deleted from function.array-search by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-217945@lists.php.net to get a copy of this message
Note Submitter: robertark at gmail dot com ---- A better array_isearch would be to store all results in an array, then return the KEYS stored in $found, such as: <?php function array_isearch($str, $array){ $found = array(); foreach ($array as $k => $v) if (strtolower($v) == strtolower($str)) $found[] = $k; return $found; } ?> To use, simply have an array to search from then search it, for example: <?php function array_isearch($str, $array) { $found = array(); foreach($array as $k => $v) if(strtolower($v) == strtolower($str)) $found[] = $k; return $found; } $stored = "these are an array"; $stored = explode(" ", $stored); $compare = array("these", "are", "some", "results", "stored", "in", "an", "array"); foreach($stored as $store) { $results = array_isearch($store, $compare); foreach($results as $key => $result) echo "Key: ".$results[$key]."<br />Found: ".$compare[$result]."<br />"; } ?> Hope this helps :-) -Rob

« previous php.notes (#217945) next »