Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从PSQL结果集递归构建XML(使用PHP)_Php_Xml_Postgresql_Recursion - Fatal编程技术网

从PSQL结果集递归构建XML(使用PHP)

从PSQL结果集递归构建XML(使用PHP),php,xml,postgresql,recursion,Php,Xml,Postgresql,Recursion,我正在使用以下代码成功构建XML文档: public function build($result) { $root = $this->append(new xmlElement('data')); $root->append(new xmlElement('collection')); while($row = pg_fetch_assoc($result)){ foreach($row as $fieldname => $fie

我正在使用以下代码成功构建XML文档:

public function build($result) {

    $root = $this->append(new xmlElement('data'));
    $root->append(new xmlElement('collection'));

    while($row = pg_fetch_assoc($result)){

        foreach($row as $fieldname => $fieldvalue){
          $second = $root->append(new xmlElement($fieldname));
          $second->write($fieldvalue);
         // $seconds_child = $second->append(new xmlElement('second child child'));
         // $seconds_child->write("second's child content");
        }
    }
}
我的问题是,什么是递归的最好方法

$current = $root;
foreach($row as $fieldname => $fieldvalue) {
    $next = $current->append(new xmlElement($fieldname));
    $current->write($fieldvalue);
    $current = $next;
}
我有一种感觉,对象引用的重新分配会把事情搞砸;如果不起作用,请告诉我

我有一种感觉,对象引用的重新分配会把事情搞砸;如果不起作用,请告诉我