R, 125 bytes
function(x,i,m=array(seq(prod(x)),x),n=rbind(m,m,m),o=cbind(n,n,n),p=which(m==i,T)+x-1,r=o[p[1]:(p[1]+2),p[2]:(p[2]+2)])r[-5]
1-based.
Input is [w, h], i because R populates arrays column first.
Makes the array and then "triples" it row- and column-wise. Then locate i in the original array and find it's neighborhood. Output without i.
ngm
- 4.4k
- 9
- 29