note 38746 added to function.array-search

From: Date: Mon, 05 Jan 2004 19:57:26 +0000
Subject: note 38746 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-62966@lists.php.net to get a copy of this message
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; ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38746 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38746&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38746&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62966) next »