note 50603 added to function.array-search

From: Date: Fri, 04 Mar 2005 14:03:00 +0000
Subject: note 50603 added to function.array-search
Groups: php.notes 
Request: Send a blank email to php-notes+get-85919@lists.php.net to get a copy of this message
This drove me mad for hours. Remember that the result of array_search might return the first position in the array, which would be "0". However, I was testing for a false value by doing this: if(!$key){ return false; }else{ return true; } when you should be doing this: if($key !== false){ return $key; }else{ return false; } Also, remember that you can search multi-dimentional arrays by specifying: $key = array_search($your_val,$your_arr[0]); or use and associative array by: $key = array_search($your_val,$your_arr['array_name']); Hope this saves you all some headaches :0) ---- Manual Page -- http://www.php.net/manual/en/function.array-search.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+50603 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50603&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50603&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50603&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50603&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50603&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+50603&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#85919) next »