在PHP中,大家一般操作数组的比较多。但有时,在做后台API或者其他情况下,需要同其他平台交换数据。一般常见的有XML,JSON两种!
1:数组转换成XML
function array2xml($array, $tag) {
function ia2xml($array) {
$xml="";
foreach ($array as $key=>$value) {
if (is_array($value)) {
$xml.="".ia2xml($value)."$key>";
} else {
$xml.="".$value."$key>";
}
}
return $xml;
}
return simplexml_load_string("".ia2xml($array)."$tag>");
}
2:数组转换成JSON,直接json_encode方法即可
另外多说一句,有的时候需要将object数据转化成数组。可以通过先将此数据json_encode,然后在解码json_decode的时候,将第二个参数设置为true即可!
Heels are good
gay porn post awards and fashion recap TV specials
Immersing patrons in a magical shroud of style and
pornoObjects Of Fashion Decoration For Men