数组数据转换为xml格式 数组可以是任意维数组 无 function xmlData($data, $xml, $k=''){$p = 0;$num = 0;foreach ($data as $key=$value){if (is_numeric($key)){continue;}if (is_array($value) !empty($value)){$tmpData = xmlData($value, $xml, (($p ==
数组数据转换为xml格式
function xmlData($data, &$xml, $k='') { $p = 0; $num = 0; foreach ($data as $key=>$value) { if (is_numeric($key)) { continue; } if (is_array($value) && !empty($value)) { $tmpData = xmlData($value, $xml, (($p == 0 && $num == 0) ? '' : $key)); $xml = $p == 0 && $k == '' && $num == 0 ? '<' . $key . '>' : ''; $xml .= $tmpData . '</' . $key . '>'; $p++; } else { if ($num == 0 && $k != '') $xml .= '<' . $k . '>'; $xml .= '<' . $key . '>' . $value . '</' . $key . '>'; $num++; } } return $xml; }