Re: array_search
| From: | Edward van Bilderbeek - Bean IT | Date: | Tue, 26 Feb 2002 09:54:03 +0000 |
| Subject: | Re: array_search | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-86209@lists.php.net to get a copy of this message | ||
array_search returns the key-value of the searched value that is found... in
the first case... the returned key is 0.... because it's the first
element... however... 0 is also the same as FALSE...
you should use === (three ='s) ... it's used to compare both value and
type... (and 0 is not the same type as FALSE)...
Greets,
Edward
----- Original Message -----
From: "Roger Keays" <s354157@student.uq.edu.au>
To: <php-general@lists.php.net>
Sent: Tuesday, February 26, 2002 10:29 AM
Subject: [PHP] array_search
> Hi,
>
> Can anybody explain why the output of this script is
>
> not found
> Found!
>
> Here is the script...
>
> $legalfields = array("reasonForRepair");
> if (array_search("reasonForRepair", $legalfields) == TRUE) {
> echo "Found!<br>";
> } else {
> echo "not found<br>";
> }
> $legalfields = array("foo", "reasonForRepair");
> if (array_search("reasonForRepair", $legalfields) == TRUE) {
> echo "Found!";
> } else {
> echo "not found";
> }
> ?>
>
> Thanks in advance,
>
> Roger
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>