May 2017
Intermediate to advanced
340 pages
8h 16m
English
One of the key questions we encountered in the last section was, why should we use SplFixedArray instead of PHP arrays? We are now ready to explore the answer. We came across the concept that PHP arrays are actually not arrays rather than hash maps. Let us run a small example code in PHP 5.x version to see the memory usage of a PHP array.
Let us create an array with 100,000 unique PHP integers. As I am running a 64 bit machine, I expect each integer to take 8 bytes each. So we will have around 800,000 bytes of memory consumed for the array. Here is the code:
$startMemory = memory_get_usage();$array = range(1,100000);$endMemory = memory_get_usage();echo ($endMemory - $startMemory)." ...
Read now
Unlock full access