我尝试了几种不同的方法,直接返回SimpleXML对象,然后运行它,将其转换为多维数组,但是一旦我尝试将其返回到另一个函数,它似乎没有任何效果,它只是空白。我必须在这里遗漏一些东西,但对于我的生活,我只是看不出它是什么。
public function getSettings() {
$xml = simplexml_load_file('SETTINGS.xml');
$settings = array();
foreach ($xml->settings->page as $page) {
$settings[$page->title] = array("Navbar" => $page->navbar, "Elements" => array());
foreach ($page->element as $element){
array_push($settings[$page->title]["Elements"],
["Name" => $element->name,
"File" => $element->location,
"Style" => $element->style]);
}
}
return $settings;
}
的Settings.XML
<?xml version="1.0" encoding="UTF-8"?>
<settings>
<page>
<title>Login</title>
<navbar></navbar>
<element>
<name>Login</name>
<location>Login.php</location>
<style>Style.css</style>
</element>
</page>
<page>
<title>Dashboard</title>
<navbar>Navbar.php</navbar>
<element>
<name>Recent Punishments Table</name>
<location>RecentPunishments.php</location>
<style>Style.css</style>
</element>
</page>
</settings>