189 8069 5689

php数组转xml

  1. 代码:
    ';
    $xml .= change($arr);
    return $xml;
    }
    function change($source) {
    $string="";
    foreach($source as $k=>$v){
        $string .="<".$k.">"; 
        if(is_array($v) || is_object($v)){
            $string .= change($v);
        }else{ 
            $string .=$v;
        } 
        $string .="";
    }
    return $string;
    }
  2. 测试:
    $arr = array(
    'name' => array(
        'a' => 'aa',
        'b' => 'bb'
    )
    );
    $xml = arraytoxml($arr);
    echo $xml;
  3. 输出:
    aabb

当前题目:php数组转xml
网站地址:http://jkwzsj.com/article/jpscpd.html

其他资讯