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
https://forums.phpfreaks.com/topic/293453-foreach-skipping-rows-in-array/
Share on other sites

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.