0
如何從下面的對象中獲取數組中的Cxyabc,Cxy123和Cxy234?SimpleXMLElement數組檢索問題
$xml_element = simplexml_load_string($xml,null, LIBXML_NOCDATA);
$childId = $xml_element->Parent->ChildID;
print_r(childId);
SimpleXMLElement Object (
[@attributes] => Array (
[entity] => result
[order-value] => 1
)
[0] => Cxyabc
[1] => Cxy123
[2] => Cxy234
)
感謝您的回答,我試過下面的一個,工作正常。字符串轉換是必要的。
$test = array();
foreach($childId as $value){
$strValue = (string)$value;
array_push($test,$strValue);
}
你能發佈完整的代碼?然而'SimpleXMLElement'實現'Traversable',所以你可以使用'foreach($ instance-> children()as $ node){...}'來迭代內部集合實例。 – 2012-07-24 22:08:06
@Praveen:這是一個SimpleXML對象,它很特別。 – 2012-07-24 22:28:06
簡單但特別:) – 2012-07-24 22:34:48