Jump to content

Echoing only range of key/value pairs from array in foreach loop...


cgm225

Recommended Posts

I have a two dimensional array I create like so:

 

            $this->data[$id] = array(
                'date'       => $date,
                'note'       => $note,
            );

 

I then echo that array in a foreach loop.  My question is, once that array is filled with a bunch of keys and values, how can I echo in a foreach loop only a certain range of those keys/values. 

 

Restated, if I have 100 pairs of keys and values, how could I only echo in the foreach loop those values between and including positions 85 to 95 in the array (this is even when the $id key is not a number value).

 

Thanks in advance!  Let me know if you need any clarification.

 

yes, but what if the $id key is not numerical in value?  What if I have an array with various key values, like...

 

apple => whatever

1 => house

4 => testing

frog => green

 

...but I want to echo, in the foreach, the range of key/value pairs in the 2nd through, and including, 4th spots?

 

 

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.