childNodes as $childNode) { if ($childNode->nodeType == 1) { $childNodes =& $childNode->childNodes; if ($childNodes->length > 1) { // Recurse $resultArray[$childNode->nodeName] = $this->xmlToArray($childNode); } elseif ( ($childNode->nodeValue == '' && $keepEmpty) || ($childNode->nodeValue != '') ) { if (isset($resultArray[$childNode->nodeName])) { if (!is_array($resultArray[$childNode->nodeName])) { // We got a second value with the same key, // let's convert this element into an array. $resultArray[$childNode->nodeName] = array($resultArray[$childNode->nodeName]); } // Add the child node to the result array $resultArray[$childNode->nodeName][] = $childNode->nodeValue; } else { // This key occurs for the first time so // set it as a scalar value. $resultArray[$childNode->nodeName] = $childNode->nodeValue; } } unset($childNodes); } } return $resultArray; } } ?>