0
XML代碼(FileZilla中server.xml中)用foreach循環的第二個層次:PHP不會繼續在XML
<FileZillaServer>
<Users>
<User Name="Bill">
<Option Name="Pass">window</Option>
</User>
<User Name="Paul">
<Option Name="Pass">apple</Option>
</User>
</Users>
</FileZillaServer>
PHP代碼:
$filezilla = 'FileZilla Server.xml';
$xml = simplexml_load_file($filezilla);
foreach ($xml->Users->User as $user) {
echo "<strong>".$user['Name']."</strong><br />";
foreach ($xml->Users->User->Option as $option) {
if ($option['Name'] == "Pass") {
echo $option."<br />";
}
}
echo "<br />";
}
輸出是:
Bill
window
Paul
window
輸出應該是:
Bill
window
Paul
apple
看來,該內部的foreach重演沒有進一步打算。 我該如何解決這個問題?
謝謝。
這工作了,非常感謝你! – PhilG