Jump to content

Odd Foreach Behavior, bug??


sshelby

Recommended Posts

My host recently upgraded to PHP Version 4.4.7. After the upgrade any foreach statement using the following format suddenly stopped working.

 

foreach (array_expression as $value)

 

I diagnosed the problem by adding a print statement on the value of $value and it turns out that instead of the actual value of the element it returns an array. I replaced them with the following format and all is well but would like to understand what happened because the PHP manual lists both as valid options. Does anyone have any ideas? I couldn't find any reference to a bug or anything.

 

foreach (array_expression as $key => $value)

 

Thanks!

Link to comment
Share on other sites

Maybe the array you are accessing contains an array in each element (two-dimensional array)? your example above looks oddly declared. Shouldn't you have something like $reserved_key[0] = 'a'; or something. Or does it automatically assign the value to whatever the 0 points to? either way, maybe you should try assigning values in your array differently.

Link to comment
Share on other sites

Maybe the array you are accessing contains an array in each element (two-dimensional array)? your example above looks oddly declared. Shouldn't you have something like $reserved_key[0] = 'a'; or something. Or does it automatically assign the value to whatever the 0 points to? either way, maybe you should try assigning values in your array differently.

 

It assigns values to elements incrementally, so that shouldn't be a problem. The long method of foreach works so I'm not sure what the deal is.

 

frost110, does your host use version 4.4.7?

Link to comment
Share on other sites

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.