Home > php教程 > php手册 > 数组数据转换为xml格式

数组数据转换为xml格式

WBOY
Release: 2016-06-06 19:32:36
Original
992 people have browsed it

数组数据转换为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;
}
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template