PHP offers eight primitive types to the user. One of them being an array. An interesting aspect of PHP arrays is that they are allocated dynamically. Thus, the following code is perfectly acceptable:
The first line set the first four indexes to one through four respectively. This creates an array of size four. The second line sets index fifty to the value fifty augmenting the array size by one. Indexes five through forty nine do not exist, and attempting to access a non existing element will only raise an E_Notice level error message. The dynamic allocation of arrays allows programmers to ignore out of bounds exceptions, segmentation faults, and hours of debugging, but it also leads to a slower write time because the memory locations needed to hold the new data is not already allocated.
The Standard PHP Library offers a SplFixedArray object that pre-allocates the necessary memory thereby solving the issue of slower write times.
Which results in (a pre-allocated array)
To verify this, I ran a test that writes data to an array and an SplFixedArray and measures the time for different amounts of elements.
It is clear that the SplFixedArray has faster a write time. However, there is a significant overhead when an object is created. To test this, I ran the same test but each time I created a new data structure. From the plot, we can see that creating an array has minimal overhead, whereas creating a new SplFixedArray object and allocating the memory takes a significant more amount of time.
Lastly I wanted to see how the memory usage differs between each data structure.
The conclusion is one typical of Computer Science, trade-offs. If you are in an environment where you will need a few arrays with predetermined sizes, the SplFixedArray is the best choice. However, if you will be creating numerous arrays, or the size is unknown, then it is probably better to use the native PHP array.