note 77525 added to function.array-search
| From: | robertark at gmail dot com | Date: | Sun, 02 Sep 2007 06:20:16 +0000 |
| Subject: | note 77525 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-130087@lists.php.net to get a copy of this message | ||
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
----
Server IP: 208.69.120.35
Probable Submitter: 69.29.103.172
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/77525
Del: integrated -- https://master.php.net/note/delete/77525/integrated
Del: useless -- https://master.php.net/note/delete/77525/useless
Del: bad code -- https://master.php.net/note/delete/77525/bad+code
Del: spam -- https://master.php.net/note/delete/77525/spam
Del: non-english -- https://master.php.net/note/delete/77525/non-english
Del: in docs -- https://master.php.net/note/delete/77525/in+docs
Del: other reasons-- https://master.php.net/note/delete/77525
Reject -- https://master.php.net/note/reject/77525
Search -- https://master.php.net/manage/user-notes.php