我遇到了一个我无法解决的错误。
$unsortedArray = array (array ( 'profileId' => '32', 'profileMiniature' => '32' ,'firstName' => 'Sarmad', 'lastName' => 'Nekomanesh', 'numberOfMutualContacts' => '0' ), array ( 'profileId' => '37', 'profileMiniature' => '37', 'firstName' => 'Sophie', 'lastName' => 'Gronlund', 'numberOfMutualContacts' => '0' ) );
header('Content-type: text/xml');
$xml = new DOMDocument('1.0', 'utf-8');
foreach($unsortedArray as $v){
$profiles = $xml->createElement('profiles');
$xml->appendChild($profiles);
$profile = $xml->createElement('profile');
$profile->setAttribute('profileId', $v['profileId']);
$profile->setAttribute('profileMiniature', $v['profileMiniature']);
$profile->setAttribute('firstName', $v['firstName']);
$profile->setAttribute('lastName', $v['lastName']);
$profiles->appendChild($profile);
}
$xml->formatOutput = true;
echo $xml->saveXML();
当我在数组中只得到一个数组元素时,我完全没有错误。