tags:

views:

78

answers:

3

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?

A: 

Doesn't PHP support arrays of arrays?

SamB
Php does support arrays of arrays.
Jonathan Czitkovics
basically I want to output from $key to "ENDEVENTS".
dcp3450
@dcp3450: why don't you use an array of arrays?
SamB
+1  A: 

Not so sure if i understood all ok but, ill give a try :-D

while(array[$key]!="ENDEVENTS"){
    echo array[$key];
    $key++;
}
kviksilver
shows the first value but I think I figure out how to get rid of it.
dcp3450
A: 

Not entirely sure if I understand your question, but maybe this is helpful:

$stuff_to_print = array_slice($my_array,$key,array_search('ENDEVENTS',$my_array));

This should return an array with key values from the $key to the next 'ENDEVENTS' value

deadkarma