note 70001 added to function.array-search
| From: | jupiter at nospam dot com | Date: | Fri, 29 Sep 2006 09:25:58 +0000 |
| Subject: | note 70001 added to function.array-search | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-117823@lists.php.net to get a copy of this message | ||
Checks that array value STARTS with the string(needle), while other functions require an exact match
OR the needle can be anywhere within. This function can be manipulated to END with the needle if
needed
<?php
// returns first key of haystackarray which array valuestring starts with needlestring, is
case-sensitive
function arrayHaystackStartsWithNeedleString($haystackarray, $needlestring) {
if (is_array($haystackarray)) { // confirms array
$needlelength = strlen($needlestring); // length of string needle
foreach ($haystackarray as $arraykey => $arrayvalue) { // gets array value
$arraypart = substr($arrayvalue, 0, $needlelength); // first characters of array value
if ($needlestring == $arraypart) { // did we find a match
return $arraykey; // return will stop loop
} // end match conditional
} // end loop
} // end array check
return false; // no matches found if this far
}
?>
I haven't speed tested this, but it should be pretty quick.
----
Server IP: 66.163.161.117
Probable Submitter: 68.104.56.193
----
Manual Page -- http://www.php.net/manual/en/function.array-search.php
Edit -- https://master.php.net/note/edit/70001
Del: integrated -- https://master.php.net/note/delete/70001/integrated
Del: useless -- https://master.php.net/note/delete/70001/useless
Del: bad code -- https://master.php.net/note/delete/70001/bad+code
Del: spam -- https://master.php.net/note/delete/70001/spam
Del: non-english -- https://master.php.net/note/delete/70001/non-english
Del: in docs -- https://master.php.net/note/delete/70001/in+docs
Del: other reasons-- https://master.php.net/note/delete/70001
Reject -- https://master.php.net/note/reject/70001
Search -- https://master.php.net/manage/user-notes.php