I have an array $data and I want to print it with foreach ($data as $detail). Thing is that I want inside foreach to print previous and next element. Something like this:
$data = array(1,2,3,4,5,6,7,8);
// foreach result should look like this
8,1,2
1,2,3
2,3,4
3,4,5
4,5,6
5,6,7
6,7,8
7,8,1
Same result done differently:
You could go:
Or if brevity is an issue:
About modulo on negative numbers: http://mindspill.net/computing/cross-platform-notes/php/php-modulo-operator-returns-negative-numbers.html