即将发出警告

My following code works (it returns the value of text in 2d array). Now, this is just a proof of concept for something more I want to do (so that's why the logic is stupid)

function searchArrayFor($array, $id, $searchFor) {
    $index = 0;
    foreach ($array as $key => $value)
    {
        return $value[1];
    }
}

So I noticed in my log file, that I am constantly getting "PHP Warning: Invalid argument supplied for foreach()". Everything looks right, and returns the value I want, any ideas on why I keep getting this error? I really don't want to be spamming the log file with every page load.

using PHP version 5.3.28 (I know, really old version).

Thanks

Try this I think you might have variables that are not array

function searchArrayFor($array, $id, $searchFor) {
    $index = 0;
    if(is_array($array)) {
        foreach ($array as $key => $value)
        {
            return $value[1];
        }
    }
    // Maybe add ELSE here and do a die($array); to see which value is not array
}

I believe this will take care of your array warning, let me know if that works.

Cheers