我不太清楚为什么我的内部循环数据被添加到外部循环数据中-
我正在解析的 XML - http://pastebin.com/vGc5NhXr
我正在使用的代码 -
<?php
$dom = new DomDocument;
$dom->preserveWhiteSpace = FALSE;
$dom->load('course/Golf/imsmanifest.xml');
// get the resources element
$organization = $dom->getElementsByTagName( "item" );
echo '<ul>';
foreach( $organization as $organizationItem )
{
$unitTitle = $organizationItem->getElementsByTagName("title");
$unitName = $unitTitle->item(0)->nodeValue;
echo '<li>',$unitName,'</li>';
echo '<ul>';
$item1 = $organizationItem->getElementsByTagName( "item" );
foreach( $item1 as $myitem ) {
$title = $myitem->getElementsByTagName("title");
$author = $title->item(0)->nodeValue;
echo '<li>',$author,'</li>';
}
echo '</ul>';
}
echo '</ul>';
生成的输出 - http://codepad.org/J2vP71rd
预期输出 - http://codepad.org/uzUtehgT
让我知道我在 for each 循环中做错了什么。