views:

151

answers:

1

I'm getting the error Invalid argument supplied for foreach() even though the array being supplied appears to be a valid array. Here's my code:

print_r($keywords);
extract($product);
foreach ($keywords as $k=>$v)
{
   //stuff here
}

Here's some of the output from the print_r:

Array
(
    [0] => Array
        (
            [text] => vanguard tripod
            [language] => 
            [advertiserCompetitionScale] => 0
            [avgSearchVolume] => -1
            [lastMonthSearchVolume] => -1
        )
    .........
    [39] => Array
        (
            [text] => 63 for sale
            [language] => 
            [advertiserCompetitionScale] => 0
            [avgSearchVolume] => 6600
            [lastMonthSearchVolume] => -1
        )

)

The error I get is on the line where I do the foreach.

The array $keywords is retrieved by doing an array_merge on two similar arrays. Could that have anything to do this this?

+3  A: 

Does $products contain an element named keywords?

If so, print_r after the extract. extract is likely the issue here.

strager
ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh! you rule man
Click Upvote
can't believe it slipped my mind
Click Upvote