1

I have a simple question regarding how PHP stores an array value:

How a simple array is stored internally (the zvalues) by the PHP interpreter? Is it a continguous memory space or it is a kind of linked list & hash-tree (or some hybrid depending on his size)?

I'am asking this because the array type in PHP can be used conveniently as a simple list, stack, queue or some kind of heap (but I don't know what kind of data structure PHP uses to store them).

Thanks.

1 Answers1

2

Internally PHP just uses a simple HashTable. (First a hash lookup; upon collision there's a simple list lookup.)

By the way, there are also some special classes in the SPL http://php.net/spl.datastructures which you might want to use for special things… (Only use them if really necessary… it's mostly just not worth it.)

bwoebi
  • 23,637
  • 5
  • 58
  • 79