note 38746 deleted from function.array-search by vincent

From: Date: Mon, 05 Jan 2004 19:59:39 +0000
Subject: note 38746 deleted from function.array-search by vincent
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-62967@lists.php.net to get a copy of this message
Note Submitter: morgan AT ghostbyte DOT com ---- There is a problem with the example given in the documentation. If you look at the description, the syntax is as follows: mixed array_search ( mixed needle, array haystack [, bool strict]) However, in the example code the usage is: $key = array_search($array, "green"); // $key = 2; $key = array_search($array, "red"); // $key = 1; The needle and the haystack are reversed, and it wont work. The error is "Warning: Wrong datatype for first argument in call to array_search" It should be: $key = array_search("green", $array); // $key = 2; $key = array_search("red", $array); // $key = 1;

« previous php.notes (#62967) next »