PHP 数组占用内存分析
下面的做法会占用多大的内存?
list($appid,$openid) = ["testcontent","test"];
测试
$m0 = memory_get_usage();$k = range(1,200000);$m1 = memory_get_usage();echo round(($m1-$m0)/pow(1024,2),4) ."MB\n";foreach ($k as $i){ $n1 = "kk$i"; $n2 = "tt$i"; list($$n1,$$n2) = [$i,$i*3];}$m2 = memory_get_usage();echo round(($m2-$m1)/pow(1024,2),4) ."MB\n";$m1 = memory_get_usage();foreach ($k as $i){ $n1 = "kk$i"; $n2 = "tt$i"; $$n1 = $i+time(); $$n2 = 2*time();}$m2 = memory_get_usage();echo round(($m2-$m1)/pow(1024,2),4) ."MB\n";