我試圖將每個<outfit>Subnodes</outfit>
子節點添加到使用php的數組中。添加xml子數組php
我的實際代碼:
public static function get_outfits($username) {
$files = self::user_files($username);
$data = self::request($files['outfits']);
$data = @simplexml_load_string($data);
if ($data && count(@$data->xpath('//outfits/outfit')) > 0) {
foreach(@$data->xpath('//outfits/outfit/*') as $items) {
$response['outfits']['items'][] = array(
"url" => (string)$items['url'],
"c" => (string)$items['c'],
"c2" => (string)$items['c2'],
"displayName" => (string)$items['displayName'],
"z" => (string)$items['z'],
"id" => (string)$items['id'],
"isUgc" => (string)$items['isUgc']
);
}
}
return (isset($response) ? $response : false);
}
XML文檔如下所示:http://outfits.zwinky.com/users/220/287/_perverted/outfits.xml
可悲的代碼是每一個現有的子保存到一個數組中。但我試圖爲每個<outfit></outfit>
節點創建一個數組索引,它應該包含子元素。
例如:
數組[0] =第一<outfit><outfit>
陣列之間一切[1] =第二<outfit><outfit>
之間一切沒有人有一個想法,如何創建這個?
您可以通過刪除所有'@'錯誤沉默開始,檢查每一個語句的任何錯誤。顯示任何你發現的東西可能會告訴你什麼是錯的,沒有任何我們的幫助! – RiggsFolly
靜音與類中的其他代碼有關。它的工作原理,但它不工作,因爲我想它的工作。該代碼確實返回任何子元素。但可悲的是,每個孩子都在陣列中。這實際上是我想要的:數組[0] =第 陣列之間的一切[1] =介於兩者之間的第二 –
d4nex
_IT的作品,但它不是工作,我希望它WORK_ ** =它不起作用** – RiggsFolly