sahil80 Posted August 15, 2008 Share Posted August 15, 2008 Hello, Can somebody help me sort the array returned by SimpleXMLElement I am calling the xpath method of SimpleXMLElement, which returns an array. The returned results have two records in it and i have to swap them for sorting purposes. but i just cannot do it as soon as i copy the item at index 1 to index 0 the array is lost. My zero index is set to null. I have tried so many options with it but no luck. How can i sort the items here? since i cannot just try to move the indexes. It seems SimpleXMLElement returns pointers to original objects in the XMLDocument. I have even tried array_merge_recursive to generate a third array but as soon as i make changes to third array my original array is lost. Please help $xmlStr = file_get_contents("example.xml"); $simxml = new SimpleXMLElement($xmlStr); $res = $simxml->xpath("/CommandList/CheckRouting/RouterList/Router/"); $objItem = $res[0]->GroupList->Group[0]->OutwardList->Outward[0]; //Line that has problem. When i assign index 1 to index 0 and reprint the results the zero index is lost $res[0]->GroupList->Group[0]->OutwardList->Outward[0] = $obj = $res[0]->GroupList->Group[0]->OutwardList->Outward[1]; print_r($res[0]); Quote Link to comment https://forums.phpfreaks.com/topic/119819-simplexmlelement-sorting/ Share on other sites More sharing options...
JonnoTheDev Posted August 15, 2008 Share Posted August 15, 2008 Can you show us the original array and how you would like it sorted Quote Link to comment https://forums.phpfreaks.com/topic/119819-simplexmlelement-sorting/#findComment-617314 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.