You are here: Re: array_search troubles « PHP Programming Language « IT news, forums, messages
Re: array_search troubles

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.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация