這是我的示例對象。我需要使用數組訪問對象。但我不能訪問這個場景的數組,因爲特殊字符(@)是前綴。所以請幫助我如何訪問陣列。在特定字符的php中關聯數組的關鍵更改
SimpleXMLElement Object
(
[@attributes] => Array
(
[Reference] => 758
[Key] => P201602161758028991205395
)
)
這是我的示例對象。我需要使用數組訪問對象。但我不能訪問這個場景的數組,因爲特殊字符(@)是前綴。所以請幫助我如何訪問陣列。在特定字符的php中關聯數組的關鍵更改
SimpleXMLElement Object
(
[@attributes] => Array
(
[Reference] => 758
[Key] => P201602161758028991205395
)
)
您可以訪問單個屬性直接作爲@簡的答案節目。
如果你需要抓住所有的屬性作爲一個真正的數組,這是做這件事:
$attributes = current($element->attributes());
我寧願這是一個緊張的,濃縮的方式來抓住所有的屬性沒有循環數組。
Objects!== arrays ....如果您需要訪問屬性,然後使用[SimpleXMLElement :: attributes](http://www.php.net/manual/en/simplexmlelement.attributes.php) –
'$ obj - > {'@ attributes'} ['Key']' – h2ooooooo
請RTFM,示例#5,訪問屬性:http://php.net/manual/en/simplexml.examples-basic.php – deceze