PDA

View Full Version : FYI... array_search error


Bernie in HK
16th of April 2002 (Tue), 13:04
FYI...

I've been having problems with photo.php giving me an error message saying that "array_search" is undefined. I've queried this with my hosting provider (http://www.avidhosting.com) and have received the following work-around:

> This function will be supported in the next version of
> PHP which will be rolled out shortly. The server
> presently has 4.0.4pl1.
> Looking at the PHP.net site manual it gives this
> workaround.
>
> For those with php source of your code:
>
> function array_search($str, $vars)
> {
> foreach ($vars as $key => $val)
> {
> if ($val == $str)
> {
> return $key;
> }
> }
> }


I've tested the work-around and it works just fine. Hopefully, this may help some of you with the same problem.


Regards,
Bernie

Pekka
16th of April 2002 (Tue), 16:04
Thanks for the help,

Note that you must remove all >'s from the code:

function array_search($str, $vars)
{ foreach ($vars as $key => $val)
{
if ($val == $str)
{
return $key;
}
}
}



NOTE that you only need this in photo.php - nowhere else and ONLY if you run PHP 4.04 or older.

If you get "Fatal error: Cannot redeclare array_search()" with this code, you already have PHP 4.05 or newer and hence don't need this code :)