on-internet
← Community

Get first key in a (possibly) associative array?

Stack Overflow ·

What's the best way to determine the first key in a possibly associative array? My first thought it to just foreach the array and then immediately breaking it, like this: foreach ($an_array as $key => $val) break; Thus having $key contain the first key, but this seems inefficient. Does anyone have a better solution?

Comments

Sign in or sign up to comment and upvote.

No comments yet.