I'm playing around with the PHP RecursiveDirectoryItorator, but I found that for some reason some of my variables are out of scope when they should be in scope... unless I'm really missing something. the two variables I'm trying to access are the $master_array, and the $current, both of witch do not have any values if i echo or print_r them in my else statement. here is my code:
$master_array = array();
$startpath = "some file path"; // i'm using a real file path in my code.
$ritit = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($startpath), RecursiveIteratorIterator::CHILD_FIRST);
foreach($ritit as $fileinfo) {
echo "<pre>";
$current = '';
if(!$fileinfo->isFile()) {
if(strip_replace($fileinfo->getFilename()) == strip_replace('some - title')) {
$master_array[$fileinfo->getFilename()] = $fileinfo->getPathname();
$current = $fileinfo->getFilename();
}
} else {
if(!empty($current) && in_array($current, split_file_path_into_array($fileinfo->getPathname()))) {
echo $fileinfo->getFilename()."
";
echo $fileinfo->getPathname()."
";
}
echo $current; // i don't have access to this
print_r($master_array); // and i don't have access to this.
}
}
any help with this would be greatly appreciated. I hope I'm just overlooking something simple, but I've been looking at this code, and messing with it for quite some time, and can't seem to get it to work.