• php数组转xml


    $ar array
        "auth" => array
            "user" => "customer",
            "password" => "password",
            "context" => "4",
        ),
        "owner" => array
            "user" => "customer2",
            "context" => "4",
        ),
        "language" => "en",
        "task" => array
            "code" => "0130",
        ), 
    );
    $xml = simplexml_load_string('<request />');
    create($ar$xml);
    echo $xml->saveXML();
     
    function create($ar$xml) {
        foreach($ar as $k=>$v) {
            if(is_array($v)) {
                $x $xml->addChild($k);
                create($v$x);
            }else $xml->addChild($k$v);
        }
    }
     
    /* 结果显示
    <?xml version="1.0" ?> 
    <request>
        <auth>
            <user>customer</user> 
            <password>password</password> 
            <context>4</context> 
        </auth>
        <owner>
            <user>customer2</user> 
            <context>4</context> 
        </owner>
        <language>en</language> 
        <task>
            <code>0130</code> 
        </task>
    </request>
    */
  • 相关阅读:
    codefoces 1405 D Tree Tag
    洛谷P3413 萌数
    数位DP模板
    leetcode 统计所有可行路径
    Josephus Transform 加速置换
    牛客IOI周赛18-提高组 排列
    Find a way HDU
    Oil Deposits HDU
    Fire! UVA
    Pots POJ
  • 原文地址:https://www.cnblogs.com/M-D-Luffy/p/4929359.html
Copyright © 2020-2023  润新知