php-general | 2001062
Date: 06/21/01
- Next message: Grimes, Dean: "RE: [PHP] setcookie() woes"
- Previous message: Gyozo Papp: "Re: [PHP] Problem sending mail with php"
- Next in thread: Jay Paulson: "[PHP] php.ini and mail"
- Reply: Jay Paulson: "[PHP] php.ini and mail"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello,
you mixed array_search(...) with in_array(...).
<manual>
mixed array_search (mixed needle, array haystack, bool strict)
Searches haystack for needle and returns the key if it is found in the array, FALSE otherwise.
</manual>
Therefore, in the 1st example it returns 0 and it was converted to FALSE by PHP, so you didn't get the expected result. You should test if there is any match in the array:
if(($key = array_search("val1",$myarray)) !== false)
{
print "Value found at :". $key;
}
"Steen Rabol" <srj <email protected>> wrote in message news:9gpgpc$vqg$1 <email protected>
> Hi
>
> How to figure out of a value is found using array_search ?
>
> eg:
>
> $myarray = array("val1","val2","val3");
> if(array_search("val2",$myarray))
> {
> print "Value found";
> }
>
> the above will work, but...
>
> if(array_search("val1",$myarray))
> {
> print "Value found";
> }
>
> the above will not work as "val1" is key 0, how can I solve this ?
>
> Thanks in advance
>
> Steen
>
>
>
Papp Gyozo
- pgerzson <email protected>
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe <email protected> For additional commands, e-mail: php-general-help <email protected> To contact the list administrators, e-mail: php-list-admin <email protected>
- Next message: Grimes, Dean: "RE: [PHP] setcookie() woes"
- Previous message: Gyozo Papp: "Re: [PHP] Problem sending mail with php"
- Next in thread: Jay Paulson: "[PHP] php.ini and mail"
- Reply: Jay Paulson: "[PHP] php.ini and mail"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

