如图所示:

JSON字符串格式:

$strJson = '{"APPID":"wxb894baf87da7b043","MCH_ID": 1517272941,"NONCE_STR": "MtwS7SGqRIBat6yT","PREPAY_ID": "wx25162041735041e7f92689191844942960","RESULT_CODE":"SUCCESS","RETRUN_CODE":"SUCCESS","RETURN_MSG":"OK","SIGN":"243872A3A46265CE6704879B203CE58A","TRADE_TYPE":"JSAPI"}';

JSON字符串转Array格式:

$arr = json_decode($strJson, true);

Array转XML格式:

$xml = array_to_xml($arr);
// 自定义函数
function array_to_xml($array){
        if( !is_array($array) || empty($array)) return ;
 
        $xml = "<xml>";
        foreach ($array as $key=>$val){
            if ( is_numeric($val) ){
                $xml .= "<".$key.">".$val."</".$key.">";
            }else{
                $xml .= "<".$key.">".$val."</".$key.">";
            }
        }
        $xml .= "</xml>";
        return $xml;
}

XML转Array格式:

$arr = xml_to_array($xml);
// 自定义函数
function xml_to_array($xml){
        $p = xml_parser_create();
        xml_parse_into_struct($p, $xml, $vals, $index);
        xml_parser_free($p);
        $data = [];
        foreach ($index as $key=>$value) {
            if($key == 'xml' || $key == 'XML') continue;
            $data[$vals[$value[0]]['tag']] = $vals[$value[0]]['value'];;
        }
        return $data;
}