I have a class that parses XML documents into an array.
I have 2 XML documents I want to parse and want to create a new class object on the fly using a foreach loop and the DirectoryIterator functions.
so far this is my attemp:
$settingsIterator = new DirectoryIterator(SETTINGS_PATH);
foreach ($settingsIterator as $fileInfo) {
if ($fileInfo->isFile()) {
$xmlFileObjName = strtolower(str_replace(".xml", "", $fileInfo->getFilename()));
${$xmlFileObjName} = new XML();
${$xmlFileObjName}->loadXML(SETTINGS_PATH . $fileInfo->getFilename());
}
}
but of course this won’t work. Is there a method to accomplish something like this?
My end goal is to have my script on execution iterate through my settings folder and create new XML object from each xml file in the directory.
If you have to access these XML objects later, better idea is to stroe them in associative array: