How Do I Reference Objects Like Arrays

From time to time, you may find yourself in the position of needing to interact with an object’s data as if it’s an array. The solution is to implement PHP’s ArrayAccess interface. I’ll show you how in this episode.
Source: Laracasts