Help with getting surrounding values in a 2D array

I’m currently working on a inventory system similar to what you would find in Apocalypse Rising 2 and I’m using a 2D array to keep track of which cells are occupied and which aren’t occupied. I can’t seem to find the values that surround another one (example below). I should also be able to define how many values I’m able to get. For example, if I have an item that takes up a 2x2 space in my inventory, I would only want to find values in a 2x2 area in the array. Does anyone know how I would go about doing this?

image

Since it’s 2d you can get it’s neighbors like so below :point_down:

That’s a very simple yet effective solution to my problem! Thank you for this, I will be adapting this so it suits my needs.