Jump to content

foreach skipping rows in array?


bazianm

Recommended Posts

I have a simple foreach loop. The array has four rows in it. Really simple. I have confirmed the data in the array with var_dump. For some reason I cannot fathom, the loop is only processing rows 0 and 2 and is not processing 1 and 3.

 

Here's the code snippet:

<?php
    foreach ($postCals as $key=>$cal){
        var_dump($postCals, $cal, $key);
        echo '<td style="text-align:right;>' . $cal . "</td>";
    }
?>

$postCals has precisely 4 values. Here's the output from this part of the code (in terms of the var_dumps).

 

array (size=4)
0 => string '2.00000' (length=7)
1 => string '2.00000' (length=7)
2 => string '3.20000' (length=7)
3 => string '4.00000' (length=7)
string '2.00000' (length=7)
int 0
array (size=4)
0 => string '2.00000' (length=7)
1 => string '2.00000' (length=7)
2 => string '3.20000' (length=7)
3 => string '4.00000' (length=7)
string '3.20000' (length=7)
int 2

 

That's it. I two other foreach loops identical to this and they run fine!

 

Any ideas?

 

(misc info:

 

php: 5.4.7 running on XAMPP/Windows

)

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.