code: public static function convertPhpObjToDom ($arr, $node, $dom)
      {
          if (is_array($arr)) {
              /**
               * If arr has integer keys, this php-array must be converted in
               * xml-array representation (<array><item>..</item>..</array>)
               */
              $arrayParam = array();
              foreach ($arr as $k => $v) {
                  if (is_integer($k)) {
                      $arrayParam[] = $v;
                  }
              }
              if (0 < count($arrayParam)) {
                  $node->appendChild($arrayDom = $dom->createElement("array"));
                  foreach ($arrayParam as $key => $val) {
                      $new = $arrayDom->appendChild($dom->createElement('item'));
                      self::convertPhpObjToDom($val, $new, $dom);
                  }
              } else {
                  foreach ($arr as $key => $val) {
                      $new = $node->appendChild(
                          $dom->createElement(self::encode($key))
                      );
                      self::convertPhpObjToDom($val, $new, $dom);
                  }
              }
          } elseif (!is_object($arr)) {
              $node->appendChild($dom->createTextNode(self::encode($arr)));
          }
      }
docs: converts php-structure to DOM-object.
  
  @param array $arr php-structure
  @param SimpleXMLElement $node parent node where new element to attach
  @param DOMDocument $dom DOMDocument object
  @return SimpleXMLElement