note 103286 deleted from function.strpos by danbrown
| From: | danbrown@php.net | Date: | Tue, 05 Apr 2011 20:55:48 +0000 |
| Subject: | note 103286 deleted from function.strpos by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-178531@lists.php.net to get a copy of this message | ||
Note Submitter: jon at theoptia dot com
----
To akarmenia at gmail dot com:
Your strpos_array function fails to return false if none of the array needles are found in the
haystack. You need to add a "return false;" as shown below.
function strpos_array($haystack, $needles) {
if ( is_array($needles) ) {
foreach ($needles as $str) {
if ( is_array($str) ) {
$pos = strpos_array($haystack, $str);
} else {
$pos = strpos($haystack, $str);
}
if ($pos !== FALSE) {
return $pos;
}
}
return false;
} else {
return strpos($haystack, $needles);
}
}