note 92427 modified in function.in-array by danbrown

From: Date: Thu, 23 Jul 2009 18:51:48 +0000
Subject: note 92427 modified in function.in-array by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-158659@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: <?php $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. --was-- 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. http://php.net/manual/en/function.in-array.php

« previous php.notes (#158659) next »