How do I print array values in a range when values are supplied?

Posted by dcp3450 on Stack Overflow See other posts from Stack Overflow or by dcp3450
Published on 2010-04-01T19:53:00Z Indexed on 2010/04/01 20:03 UTC
Read the original article Hit count: 125

Filed under:
|
|

My php reads in xml and I want to ouput the values within a given range. I have no way of knowing the size of the array or the range. However, I do know where to start; I have a $key that holds my current location. I also know where to stop; I have the word "ENDEVENTS" between each set. I want to get the values from my current position ($key) to my end position ("ENDEVENTS").

for example i may have an array set like this:

Array(
 [0]=1
 [1]=apple
 [2]=straw
 [3]=bike
 [4]=ENDEVENTS
 [5]=15
 [6]=hair
 [7]=shirt
 [8]=nose
 [9]=kiwi
 [10]=ENDEVENTS
 )

My code knows when I'm on 15 (in this example $key=5). I want to print 6 through 9. I tried using foreach but it's thats causing issues with what I'm trying to produce.

Any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays