What is the internal difference between an Array and a SplFixedArray in terms of memory and performance?
Last updated
A PHP
arrayis an ordered hash map supporting any keys and growth, but each element carries hashing and bucket overhead.SplFixedArrayhas a fixed size and integer keys 0 to size-1, stored in a contiguous block ofzvalslots. This means less memory and slightly faster indexed access.Tradeoffs: no string keys, manual resizing via
setSize(), and object (not array) semantics. Modern packed arrays narrow the gap, so use it mainly for very large fixed numeric collections.