You can do it with array and loops, but I think it would be much easier to use "Is overlapping" event.
Make item's collision polygon a bit smaller than the slot, or several slots for big items. Create an instance variable isOccupied on slot sprite.
When player is dragging and dropping the item to the inventory, test if it's overlapping an empty inventory slot, and not overlapping occupied slots or the border around the inventory area.
When the inventory layer is hidden and player picks up an item off the ground, you can pick all empty slots, do "For each slot", set item position to each slot, test if it's overlapping occupied slots/border. Repeat the loop until you find a suitable slot(s).