3 ms·
> It would be nice to have separate types for arrays and hash tables though. I don't understand why they were combined to begin with. Simplicity? Seems like the
by _RPM 12y ago
> It would be nice to have separate types for arrays and hash tables though. I don't understand why they were combined to begin with. Simplicity? Seems like there are more edge cases and gotchas the way things are now.
There is no "hash table" type in PHP user land.
- imaginenore 12y agoThere are no arrays in PHP. There are only hash tables that are called "array" for simplicity.
- colordrops 12y agoHow do they maintain their order?
- Retra 12y agoYou put things in order by memory address and they stay in order when you access them. An array is just a special case of a hash map -- one with a trivial hash function. That's why the lend themselves to the same syntax so well.
- _RPM 12y agoBy using a doubly linked list, where the first element in the "bucket", contains the next pointer to the next element in the hash table. Read zend_hash.h & zend_hash.c It is fairly complicated and explaining it in depth is beyond the scope of this comment. This "bucket" also handles the collisions by using separate chaining. There is actually two "next" pointers, one for the chains, and one for the next element in order of insertion. Very confusing and requires reading through the code and playing with it.
- patkai 12y agoYou made my day, guys, please don't stop :)
- jakobegger 12y agoThey aren't really hash tables either, because they additionally store the order of the keys (in a normal hash table, order would be arbitrary)
- adunn 12y agoYou're right, thanks for pointing that out.
- deleted 12y ago[deleted]