我想转换这个给定的数组
array(
'podcast' => array(
(int) 0 => array(
'Podcast' => array(
'id' => '2',
'xmlurl' => 'http://test2.com'
)
),
(int) 1 => array(
'Podcast' => array(
'id' => '4',
'xmlurl' => 'http://test4.com'
)
)
)
)
使用 CakePHP 2.3.6 进入这个字符串:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<opml version="2.0">
<head></head>
<body>
<outline xmlUrl="http://test2.com" />
<outline xmlUrl="http://test4.com" />
</body>
</opml>
我该怎么做?我知道这里有一个Doc,但我还是很感激帮助。
这是我到目前为止所拥有的:
$new = array();
foreach($podcasts as $p):
$pod['xmlurl'] = $p['Podcast']['xmlurl'];
endforeach;
$new['opml']['body']['outline'][]=$pod;
debug($new);
$xmlObject = Xml::fromArray($new);
$xmlString = $xmlObject->asXML();
debug($xmlString);
输出debug($xmlString)
:
'<?xml version="1.0" encoding="UTF-8"?>
<opml>
<body>
<outline>
<xmlurl>http://test1.com</xmlurl>
</outline>
</body>
</opml>'