Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.