note 10165 added to in_array
| From: | Doc at php2 dot chek dot com | Date: | Sat, 16 Dec 2000 03:28:11 +0000 |
| Subject: | note 10165 added to in_array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-8778@lists.php.net to get a copy of this message | ||
The reason that in_array returns True or False rather than the index is probably that what
you're looking for might be found at location 0 of the array. You do something like
if(in_array("duh",$bluh)). If $bluh[0]=="duh", the logic of the if() statement
is defeated.
Solution? Create another function, perhaps where_in_array(), or have in_array() return -1 if and
only if the element is not found. (But then, it would be very easy to get confused while using
in_array() and forget that 0 might actually be a valid result, and fall into the broken if() clause,
above.)
http://www.php.net/manual/function.in-array.php