检查PHP数组占用的内存量

时间:2013-07-15 14:10:33

标签: php memory

有没有简单的方法来检查某个数组占用多少内存?

就像我有一些10k行数组,需要知道服务器在一些$arr内记住它需要多少MB / KB

2 个答案:

答案 0 :(得分:1)

答案 1 :(得分:1)

// how much memory are you using before building your array
$baseMemory = memory_get_usage(false);
// create your array
$a = array('A',1,'B',2);
// how much memory are you using now the array is built
$finalMemory = memory_get_usage(false);
// the difference is a pretty close approximation
$arrayMemory = $finalMemory - $baseMemory;