PHP 对象-数组转换

来源:互联网 发布:sql case when else 编辑:程序博客网 时间:2024/06/05 16:07

使用json_encode和json_decode函数实现数组-对象转换

$xmlData = <<<EOD<?xml version="1.0" encoding="UTF-8"?><note><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>EOD;// 创建XML对象$xmlOB = simplexml_load_string($xmlData);// 打印XML对象echo "<pre>";print_r($xmlOB);// 转换XML对象为数组$xmlArr = json_decode(json_encode($xmlOB), True);//打印XML对象print_r($xmlArr);

打印输出

SimpleXMLElement Object(    [to] => Jason    [from] => Lemone    [heading] => party    [body] => Don't forget this weekend!)Array(    [to] => Jason    [from] => Lemone    [heading] => party    [body] => Don't forget this weekend!)

欢迎加入PHP技术交流群(478642311)

0 0
原创粉丝点击