When I'm testing array_map()
function. There is a very strange phenomenon.
Normal size array
$array = range(1, 100000);
echo memory_get_usage();
array_map(function($value) {}, $array);
echo memory_get_usage();
Result
8649024
8649024
It's obvious that the memory size is equal.
But for big array
$array = range(1, 10000000);
echo memory_get_usage();
array_map(function($value) {}, $array);
echo memory_get_usage();
Result
84319040
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 36 bytes) in G:\phpStudy\WWW\testSpeed.php on line 6
Why? I have search answer everywhere. But it seems that there are few people have this problem. If anyone can help me? Thank you!