note 69379 added to function.in-array

From: Date: Sun, 03 Sep 2006 20:11:45 +0000
Subject: note 69379 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-116645@lists.php.net to get a copy of this message
I didn't find this anywhere in the manual or in the notes. I'm sorry if this is a repetition, but I just found this out the hard way :( If the haystack array contains only ONE element, then in_array will give this warning: Wrong datatype for second argument in call to in_array() This can be fixed by explicitly typecasting the haystack array to an array. <? $haystack = (array) $haystack; if(in_array($needle, $haystack)) return true; else return false; ?> ---- Server IP: 66.163.161.117 Probable Submitter: 202.70.153.49 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/69379 Del: integrated -- https://master.php.net/note/delete/69379/integrated Del: useless -- https://master.php.net/note/delete/69379/useless Del: bad code -- https://master.php.net/note/delete/69379/bad+code Del: spam -- https://master.php.net/note/delete/69379/spam Del: non-english -- https://master.php.net/note/delete/69379/non-english Del: in docs -- https://master.php.net/note/delete/69379/in+docs Del: other reasons-- https://master.php.net/note/delete/69379 Reject -- https://master.php.net/note/reject/69379 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#116645) next »