xml方式封装通信数据方法

xml方式封装通信数据方法

public static function xmlToEncode($data) {
  
    $xml = "";
    foreach($data as $key => $value) {
        $attr = "";
        if(is_numeric($key)) {
            $attr = " id='{$key}'";
            $key = "item";
        }
        $xml .= "<{$key}{$attr}>";
        $xml .= is_array($value) ?

self::xmlToEncode($value) : $value; $xml .= "</{$key}> "; } return $xml; }



原文地址:https://www.cnblogs.com/blfbuaa/p/6930638.html