note 10165 deleted from function.in-array by jimw

From: Date: Fri, 07 Dec 2001 21:06:55 +0000
Subject: note 10165 deleted from function.in-array by jimw
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-21965@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.)

« previous php.notes (#21965) next »