Re: search array for value
| From: | Lenar | Date: | Tue, 31 Jul 2001 09:18:38 +0000 |
| Subject: | Re: search array for value | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-60361@lists.php.net to get a copy of this message | ||
> > How do I search an array?
> >
> > For example if I want to know if $array contains "1"...
> >
> > Regards,
> >
> > Matthew Delmarter
> >
>
This is bad, use in_array() or array_search().
in_array() returns TRUE if element is found in array.
array_search returns the key of matching element, FALSE otherwise.
Lenar
> for ($i = 0; $i < count($array); $i++)
> {
> if ($array[$i] == 1) {
> //do something
> exit;
> }
> }
>