Re: Question about array_search
| From: | Robin Vickery | Date: | Mon, 11 Oct 2004 16:49:35 +0000 |
| Subject: | Re: Question about array_search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-199207@lists.php.net to get a copy of this message | ||
On Mon, 11 Oct 2004 09:07:13 -0700, Brian Dunning
<brian@briandunning.com> wrote:
> The problem is that if the item is at index 0 in the array, array_search gives the
> same answer as if it's not in there at all.
No it doesn't.
If it's in index 0 it returns 0, if it's not there at all it returns FALSE.
you need to use something like:
if (array_search($needle, $haystack) === false) {
// add $needle to $haystack
}
http://lv.php.net/array-search
http://php.net/manual/en/language.operators.comparison.php
-robin