有什么简单的方法可以检查某个数组需要多少内存?
就像我有一些 10k 行数组,需要知道服务器需要多少 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;
您可以查看以下函数: http: //php.net/manual/en/function.memory-get-usage.php