Array ([0] =>
SimpleXMLElement Object ([record] =>
SimpleXMLElement Object ([f] =>
Array ([0] => Company
[1] => Company
[2] => Mark Test
[3] => Intern
[4] => Administrative
[5] => Account
[6] => img.png
[7] => SimpleXMLElement Object ([@attributes] => Array ([id] => 18))
[8] => SimpleXMLElement Object ([@attributes] => Array ([id] => 21))
[9] => [email protected]
[10] => SimpleXMLElement Object ([@attributes] => Array ([id] => 178))
[11] => SimpleXMLElement Object ([@attributes] => Array ([id] => 177))
[12] => SimpleXMLElement Object ([@attributes] => Array ([id] => 179))
[13] => SimpleXMLElement Object ([@attributes] => Array ([id] => 168)))
[update_id] => 12102222262043)))
這基本上是我simplexmlobject數組,我想以某種方式只是操縱並從f元素開始取出數據。我想將公司,Mark Test,Intern等字樣存儲到數組中。我似乎無法弄清楚我是如何在PHP中使用foreach循環做到這一點的,並且這種結構非常瘋狂。麻煩存儲SimpleXMLElement對象到數組
好讓這個數據是我在代碼中getUsers()做一個API調用,這給了我一個simplexml的服務部分做了這一切的價值觀:
$xml = $getUser->getUsers();
$records = $xml->xpath('//records');
print_r($records);
所以,你要拿出後的一切,包括文檔中'F'?另外,封閉'Array'從哪裏來?你能發佈生成這個輸出的代碼嗎? – 2011-06-15 21:39:13
是的我想要所有這些元素到一個不那麼複雜的數組中。 – Novazero 2011-06-15 21:41:20
你可能最好使用DOMDocument而不是SimpleXML。我很樂意使用DOMDoment編寫一個例子,但是當涉及到這種類型的東西時,SimpleXML有點太麻煩了......我應該知道,我實際上用SimpleXML修復了一個數組的問題,但它不會出來直到PHP 5.4發佈。 – 2011-06-15 21:44:29