I have an array of variabel length, containing events sorted by startdate, looking like this:
Array
(
[0] => stdClass Object
(
[id] => 1978
[date] => 2012-09-29
)
[1] => stdClass Object
(
[id] => 1979
[date] => 2012-10-14
)
...etc....
I need to make a function that takes one of the event, and puts in the middle of a new array with a length of exactly seven, and puts the event's neighbours on each side.
So if event 5 passed to the function, the output should be:
[2][3][4][5][6][7][8]
If the first event is passed to the function, and the original amount of events is 12, the output should be:
[10][11][12][1][2][3][4]
If the orignal amount of events is 6, and the fifth event is passed, the output should be:
[2][3][4][5][6][1][]
So the list of events should always "wrap around" in the new array and fill it up as much as possible.
I have hacked together a solution, that involves quite a bit of steps. I dont really like it, and it got me wondering:
How would this be done in the most efficient and elegant way?
ksort()orusort()?