How does the Zend Engine's Hash Table implementation allow PHP arrays to function as both lists and associative maps?

Last updated 15 June 2026

  • 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 foreach iterates 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.

  • https://centamori.com/index.php?slug=arrays-in-php
  • https://www.scribd.com/document/94966855/13104643-Php-Documents-Oops
  • https://dev.to/ali_algmass/hash-tables-demystified-a-complete-guide-with-php-implementation-4fc9
All PHP interview questions