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?

1
  • In case it isn't clear, i've snipped the print_r from element 0 to element 39, the .... you see is added by me, it isn't there in the actual output Commented May 30, 2009 at 6:26

1 Answer 1

3

Does $products contain an element named keywords?

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.