note 94206 added to function.in-array

From: Date: Thu, 22 Oct 2009 10:12:52 +0000
Subject: note 94206 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-161972@lists.php.net to get a copy of this message
@ Will Reiher : Your function to check whether or not a string is in a simple array is not that good, here is why : <?php //your function : $bool = stristr(implode(' ', $array), $word); //note that the returned value is noot a boolean, it's false only when the word is not found ... anyway //lets say i got an array : $array = array("str","ing"); //and a string : $word = "str ing"; //now with your "function" : $result = stristr(implode(' ', $array), $word); //the string is NOT present in the array BUT $result is NOT false //so your function don't work as expected ?> Thats why you better use in_array(); function. ---- Server IP: 89.31.146.176 Probable Submitter: 89.158.217.62 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/94206 Del: integrated -- https://master.php.net/note/delete/94206/integrated Del: useless -- https://master.php.net/note/delete/94206/useless Del: bad code -- https://master.php.net/note/delete/94206/bad+code Del: spam -- https://master.php.net/note/delete/94206/spam Del: non-english -- https://master.php.net/note/delete/94206/non-english Del: in docs -- https://master.php.net/note/delete/94206/in+docs Del: other reasons-- https://master.php.net/note/delete/94206 Reject -- https://master.php.net/note/reject/94206 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161972) next »