title: PHP foreach print array with previous and next element
body: <p>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:</p>
  
  <pre><code>$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
  </code></pre>