|
Posted by JP on 01/08/08 21:31
Thanks for the reply:
I had read that box and now have re-read it and am still confused.
The warning states:
"Warning
This function may return Boolean FALSE, but may also return a non-
Boolean value which evaluates to FALSE, such as 0 or "". Please read
the section on Booleans for more information. Use the === operator for
testing the return value of this function."
This warning says to me that I cannot use something like
if (array_search($key,$keys))
{...}
because match on the array index [0] which would return 0 is similar
to returning FALSE.
Upon further consideration however, I decided to do something like
this (which works)
$retval = array_search($key, $keys);
if ($retval)
{
echo "Match found\n";
}
else
{
if ($retval === 0)
{
echo "Match found\n";
}
else
{
echo "Match not found\n";
}
}
So it appears that if a FALSE is returned by the function but the 0
return value really means it matched key [0] in the haystack, you
should check for this with the === operator.
[Back to original message]
|