note 92427 added to function.in-array

From: Date: Thu, 23 Jul 2009 18:42:58 +0000
Subject: note 92427 added to function.in-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-158658@lists.php.net to get a copy of this message
in_array() and array_search() are not identical. While trying to track down a bug, I discovered that this would produce a match: $raw_data_item_types = array(0,5,9,'g','I'); $item="?gopher" if(true===in_array($item, $raw_item_types)) { ... } Obviously not the desired result! Replacing all instances of in_array with array_search() solved the immediate problem of not producing a match when there wasn't one to begin with. ---- Server IP: 64.71.164.2 Probable Submitter: 76.183.194.16 ---- Manual Page -- http://www.php.net/manual/en/function.in-array.php Edit -- https://master.php.net/note/edit/92427 Del: integrated -- https://master.php.net/note/delete/92427/integrated Del: useless -- https://master.php.net/note/delete/92427/useless Del: bad code -- https://master.php.net/note/delete/92427/bad+code Del: spam -- https://master.php.net/note/delete/92427/spam Del: non-english -- https://master.php.net/note/delete/92427/non-english Del: in docs -- https://master.php.net/note/delete/92427/in+docs Del: other reasons-- https://master.php.net/note/delete/92427 Reject -- https://master.php.net/note/reject/92427 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#158658) next »