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 -- h
ttps://master.php.net/note/delete/70001/integrated
Del: useless -- http
s://master.php.net/note/delete/70001/useless
Del: bad code -- htt
ps://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 -- http
s://master.php.net/note/delete/70001/in+docs
Del: other reasons-- https://mast
er.php.net/note/delete/70001
Reject -- https://mast
er.php.net/note/reject/70001
Search -- https://
master.php.net/manage/user-notes.php
--
PHP Notes Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub
.php
|