note 103286 added to function.strpos

From: Date: Tue, 05 Apr 2011 20:42:20 +0000
Subject: note 103286 added to function.strpos
Groups: php.notes 
Request: Send a blank email to php-notes+get-178530@lists.php.net to get a copy of this message
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); } } ---- Server IP: 72.55.140.6 Probable Submitter: 208.65.73.110 ---- Manual Page -- http://www.php.net/manual/en/function.strpos.php Edit -- https://master.php.net/note/edit/103286 Del: integrated -- https://master.php.net/note/delete/103286/integrated Del: useless -- https://master.php.net/note/delete/103286/useless Del: bad code -- https://master.php.net/note/delete/103286/bad+code Del: spam -- https://master.php.net/note/delete/103286/spam Del: non-english -- https://master.php.net/note/delete/103286/non-english Del: in docs -- https://master.php.net/note/delete/103286/in+docs Del: other reasons-- https://master.php.net/note/delete/103286 Reject -- https://master.php.net/note/reject/103286 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#178530) next »