title: Slice N elements from middle of array
body: <p>I want to slice 5 elemtens from an array, giving a middle index:</p>
  
  <pre><code>$a = [1,2,3,4,5,6,7,8,9,10];
  </code></pre>
  
  <p>Examples:</p>
  
  <ul>
  <li>Index: [0] => Return: <code>[1,2,3,4,5]</code></li>
  <li>Index: [3] => Return: <code>[2,3,4,5,6]</code></li>
  <li>Index: [5] => Return: <code>[4,5,6,7,8]</code></li>
  <li>Index: [9] => Return: <code>[6,7,8,9,10]</code></li>
  </ul>
  
  <p>I tried to extract left and right parts.</p>
  
  <pre><code>$i = 0 // selected index
  $right = array_slice($a,$i,2);
  $left = array_slice($a,$i-2,2);
  $index = $a[$i];
  </code></pre>
  
  <p>But it doesn't work when reaches the end (both sides).</p>