$dir = './';
$files1 = scandir($dir, 1);
$totalSize = 0;
foreach ($files1 as $fileName)
$totalSize += filesize($fileName);
echo "TOTAL FILE SIZE:". $totalSize /1024 /1024 ."<br /><br />";
foreach ($files1 as $fileName)
echo $fileName "<br />";
我这里有一个示例代码,我想把它减少到只有 1 个 foreach 循环,我想在上面打印我的 totalSize,这怎么可能?我在想是否有任何方法可以“稍后处理我的 $totalSize”
我想要实现的是这样的:
//I WANT THIS TO GET THE VALUE BELOW
echo "TOTAL FILE SIZE:". $totalSize /1024 /1024 ."<br /><br />";
foreach ($files1 as $fileName)
{
echo $fileName "<br />";
$totalSize += filesize($fileName);
}
天哪,我太傻了,我想太多了,却忘记了简单的技术。感谢帮助我回答这个问题的人!