May 2017
Intermediate to advanced
340 pages
8h 16m
English
So far, we have explored PHP arrays and we know, we do not define the size of the arrays. PHP arrays can grow or shrink as per our demand. This flexibility comes with a great inconvenience regarding memory usage. We are going to explore that in this section. For now, let us focus on creating fixed size arrays using the SPL library.
Why do we need a fixed size array? Does it have any added advantage? The answer is that when we know we only need a certain number of elements in an array, we can use a fixed array to reduce the memory usage. Before going to the memory use analysis, let us have some examples of using the SplFixedArray method:
$array = new SplFixedArray(10);for ($i = 0; $i ...
Read now
Unlock full access