RecursiveIteratorIterator空白页面
问题描述:
我正在尝试使用RecursiveIteratorIterator
和RecursiveDirectoryIterator
。RecursiveIteratorIterator空白页面
我想要在我的c:\
文件夹中获取所有文件。但我不知道为什么我不能得到结果,但一个空白页。
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('c:/'));
foreach($it as $file) {
$all[] = $file->getRealPath();
}
print_r($all);
但如果我使用此代码,它的工作
foreach($it as $key=>$file)
{
echo $key."=>".$file."\n";
}
答
这是因为PHPs StdObj
-class不能用作数组,因为它是一个关联数组。这是错误的,但我无法更好地描述它。 PHP对象被铸造或类似的东西。
如果$data
是一个对象,那么如果您想要访问$value
作为对象,则这是必需的。
foreach($data as $property => $value){
echo $value->r;
}
编辑:这是一个很好的问题btw,我花了几个小时自己搞清楚了这一点。
+1
感谢您的回答:) – Ahmad
当问这样的问题时,总是提供输出。 – hakre