Posts

Showing posts with the label associative

PHP associative arrays or hashes: in-depth look

Image
Before you start reading i warn you: this article won't help you in every day PHP developing in any way. But if you are naturally interested, like me, in how things work you're welcome to spend your precious time on reading and understanding this article. Still here? Great. Lets try to stay sane after all this low level mumbo-jumbo and start. PHP array or in other terms hash is a combination of the data storing methods called "vector" and "linked list". Vector is a nice aligned structure in the memory, simplest and fastest way to store and access linked pieces of the data because accessing vector offsets functionality is baked right into the modern CPU's. I'm referring to the assembler's offset calculating functionality like MOV [BASE+OFFSET], DATA. Think of the vectors as a numerically indexed PHP array. If you need to access array member you just pass offset to it like this: $array = array("a", "b", "c"); ...