title: Get neighbours of each two dimensional array element
body: <p>I have two-dimensional array of elements like</p>
  
  <pre><code>1 2 3 
  4 5 6
  7 8 9
  </code></pre>
  
  <p>Now how do I get neighbours of each element?</p>
  
  <p>For Ex : For 1 neighbours are [2,4] and for 2[1,3,5] etc.</p>
  
  <p>Do suggest how can I do this.</p>
  
  <p>Expected Output : </p>
  
  <pre><code>[
  1=&gt;[2,4],
  2=&gt;[1,3,5],
  3=&gt;[2,6],
  4=&gt;[1,5,7],
  5=&gt;[2,4,6,8],
  6=&gt;[3,5,9],
  7=&gt;[4,8],
  8=&gt;[7,5,9],
  9=&gt;[6,8]
  ]
  </code></pre>