PHP arrays are absolutely fantastic. They hold stuff, doesn’t really matter what. The interfacing is pretty consistent and there’s a boat load of built-in array functions. What PHP lacks is the ability to set the array pointer to an arbitrary key or value. There are ways to move forward and backward in the array but not a dedicated function to set the internal pointer to a specific key. Fortunately we can make it work, but it’s pretty archiac. We’ll need to loop through the array and look for what we want.
Like many things I post, this is more of an example than an actual use case. In my experience, it’s pretty rate that you run into a scenario where you can trust the structure of the array enough to want to set the pointer explicitly. It’s usually must easier to assume that things are a mess and that checking if a key exists is enough to suffice.
Have you ever had to hack together something like this? If so, comment below!