您好我有以下簡單的XML對象的XML標記名稱:怎樣用簡單的XML對象
[ad] => Array
(
[0] => SimpleXMLElement Object
(
[title] => <b>Title: Mysql 1</b>
[abstract] => Abstract: Mysql 1
[url] => www.Mysql.com
[rurl] => http://sample/xtrack.php?rurldata=yes
[iurl] => http://sample.com/
[bid] => 0.0880
)
[1] => SimpleXMLElement Object
(
[title] => <b>Title: Mysql 2</b>
[abstract] => Abstract: Mysql 2
[url] => www.Mysql.com
[rurl] => http://sample/xtrack.php?rurldata=yes
[iurl] => http://sample.com/
[bid] => 0.1980
)
)
我想創建這樣的數組。我想在的foreach這樣
foreach($xmlString->ad as $key){
foreach($key as $key2 => $val2){
$adData[$counter][$key2] = $val2;
}
$counter++;
}
,但我得到的結構是這樣的:
Array
(
[0] => Array
(
[title] => SimpleXMLElement Object
(
[0] => <b>Title: Mysql 1</b>
)
[abstract] => SimpleXMLElement Object
(
[0] => Abstract: Mysql 1
)
[url] => SimpleXMLElement Object
(
[0] => www.Mysql.com
)
[rurl] => SimpleXMLElement Object
(
[0] => http://sample/xtrack.php?rurldata=yes
)
[iurl] => SimpleXMLElement Object
(
[0] => http://sample.com/
)
[bid] => SimpleXMLElement Object
(
[0] => 0.0880
)
)
.
.
.So on
現在我知道,$爲key2是一個對象。我如何只能檢索標籤名稱?如何去做這件事?
如果我這樣做: '$ ADDATA [$計數器] [$ key2->的getName()] = $值2;' 我得到錯誤: '調用一個非對象的成員函數getName()在' 但它是一個對象 – Shades88 2011-12-26 11:59:31
@ Shades88:錯誤消息說明你試圖使用非對象作爲對象,你確定'$ key2'是設置正確 – RageZ 2011-12-26 12:01:38
ohhh我現在明白了。 $ key2是一個字符串。但是我得到的$ val2是一個對象。不明白這裏發生了什麼 – Shades88 2011-12-26 12:05:39