I know how to use them, but I wonder how they work under the hood, and how slow they are compared to regular arrays.
My guess is that this:
myArray['value'] = 10;
myArray['another_key'] = 11;
is translated to something like this:
myArray[0][0] = 'value';
myArray[0][1] = 10;
myArray[1][0] = 'another_key';
myArray[1][1] = 11;
- Do they actually work like this?
- What happens when I try to get a value from an associative array? How much time does it take to get a value from an associative array?
- Should I use them if my processing time is limited (e.g. inside a game loop)?
[EDIT]
Looks like my guess was wrong, and that the keys of the array are actually properties of an object. So, to collect all the answers I got in one place:
- Associative arrays are objects
- Keys are property names of said objects
- No search is done when you get a value of a specific key of the array because what you actually do is fetching the value of an object property which takes next to no time.