数组转xml

xiaoxiao2021-03-01  33

$params = [ 'appid'=> self::APPID, 'mch_id'=> self::MCHID, 'nonce_str'=>md5(time()), 'body'=>'公众号支付测试', 'out_trade_no'=>$oid, 'total_fee'=> 2, 'spbill_create_ip'=>$_SERVER['REMOTE_ADDR'], 'notify_url'=> 'https://www.liminghulian.com/test/notify.php', 'trade_type'=>'JSAPI', 'product_id'=>$oid, 'openid' => $this->getOpenId() ]; //数组转xml public function ArrToXml($arr) { if(!is_array($arr) || count($arr) == 0) return ''; $xml = "<xml>"; foreach ($arr as $key=>$val) { if (is_numeric($val)){ $xml.="<".$key.">".$val."</".$key.">"; }else{ $xml.="<".$key."><![CDATA[".$val."]]></".$key.">"; } } $xml.="</xml>"; return $xml; }

 

转载请注明原文地址: https://www.6miu.com/read-3650333.html

最新回复(0)