note 71293 rejected from function.array-search by colder

From: Date: Tue, 21 Nov 2006 14:03:52 +0000
Subject: note 71293 rejected from function.array-search by colder
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-119940@lists.php.net to get a copy of this message
Note Submitter: Elwin van Huissteden ---- Appearently, the array_search function, has a bug i found. It will not return the first array position! (exemple below) $array = array(); array_push($array,'bob'); array_push($array,'pete'); array_push($array,'andy'); array_push($array,'jib'); if (array_search('pete', $array) != Null) echo 'found'; else echo 'not found'; // returns "found" if (array_search('bob', $array) != Null) echo 'found'; else echo 'not found'; // returns "not found" !?! // this could be because of the array_push function, but it can be fixed with the following: $array = array(0 => 'not relevant'); array_push($array,'bob'); array_push($array,'pete'); array_push($array,'andy'); array_push($array,'jib'); if (array_search('bob', $array) != Null) echo 'found'; else echo 'not found'; // returns "found"

« previous php.notes (#119940) next »