Jump to content

foreach : Invalid argument supplied


williamZanelli

Recommended Posts

Hi guys,

 

Just wondering if you could tell me whats wrong with the following array

 


$array2d= array(

    5  => array(
    'fname'  =>  'Smith',
    'sname'  => 'smith'
    ),

);

 

Its had me all day, when I run it inside a foreach, it throws the following warning,

 

Warning: Invalid argument supplied for foreach()  - followed by the line number.

 

Thanks for your thoughts

 

Will

 

Link to comment
https://forums.phpfreaks.com/topic/165803-foreach-invalid-argument-supplied/
Share on other sites

Hi guys,

 

Thanks for the prompt responses.

 

The code I have is cumbersome, so I decided to keep it simple.

 

The foreach is like,

 

foreach($array2d as $key => $val) {
                if($data[$key] != '') {
                    $sql = "......"
//loads of business logic etc.

 

The error is thrown at line foreach.

 

Thanks for your thoughts

 

Will

Thanks for this guys.

 

How do I do a var dump?

 

Cheers

 

You can do:

 

print_r($array2d);
//or
var_dump($array2d);

 

Like CV said, you must be changing your array between the codes you've posted.  Please post all the code from your first except to the second.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.