How does the Zend Engine's Hash Table implementation allow PHP arrays to function as both lists and associative maps?
Last updated
PHP has one array type backed by the Zend Engine's ordered hash table (
HashTable): integer and string keys coexist, and a "list" is just sequential int keys from 0.Insertion order is stored separately from hashing, so
foreachiterates in the order keys were added.Since PHP 7, sequential 0-based keys use a compact "packed" layout that skips hashing. Adding a string or non-sequential key promotes it to a full hash.