I’m trying to use RecursiveIteratorIterator and RecursiveDirectoryIterator.
I want get all file inside my c:\ folder. But i don’t know why i can’t get the result but a blank page.
$it = new RecursiveIteratorIterator(new RecursiveDirectoryIterator('c:/' ));
foreach( $it as $file ) {
$all[] = $file->getRealPath();
}
print_r($all);
but if i use this code, it’s work
foreach( $it as $key=>$file )
{
echo $key."=>".$file."\n";
}
It’s because PHPs
StdObj-class cannot be used as an array because it’s an associative array. This is wrong by the words but I cannot describe it better. The PHP object gets casted or something like that.If
$datais an object then this is required if you want to access$valueas an object.Edit: This is a good question btw, I’ve spent a couple of hours myself figuring this out.