你好我有mysql数组到xml代码和我的代码给出错误的xml输出通常必须是父子我的数组给孩子父母:)我的代码在这里请帮助我。
function packages($limit,$type){
$ret_array = array();
$sql = "select ID,packageName,servicer,products,clients
from Packages order by ID asc limit $limit";
$result = mysql_query($sql);
while($data = mysql_fetch_object($result)){
$obj['ID'] = $data->ID;
$obj['packageName'] = $data->packageName;
$obj['servicer'] = $data->servicer;
$obj['products'] = $data->products;
$obj['clients'] = $data->clients;
$ret_array[] = $obj;
}
$xml = new SimpleXMLElement('<root/>');
array_walk_recursive($ret_array, array ($xml, 'addChild'));
print $xml->asXML();
return $ret_array;
}
并提供输出
<?xml version="1.0"?>
<root><1>ID</1><Free>packageName</Free><1>servicer</1><3>products</3><10>clients</10><2>ID</2><Basic>packageName</Basic><3>servicer</3><25>products</25><50>clients</50><3>ID</3><Advanced>packageName</Advanced><5>servicer</5><50>products</50><100>clients</100><4>ID</4><Premium>packageName</Premium><10>servicer</10><100>products</100><250>clients</250></root>
我希望这样;
**output gives example <Free>packageName i want <packageName>Free**
感谢