下面的做法会占用多大的内存?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";上面运行输出的结果如下:27.9404MB
51.3041MB
9.1553MB可见数组占用的内存远大于正常分配的内容
...
继续阅读
(42)