检查PHP数组占用多少内存

亚当·彼得拉西亚克

有什么简单的方法可以检查某个数组占用多少内存?

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

马克·贝克
// 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;

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章