2
$objDOM = new SimpleXMLElement(XML_FILE_NAME, null, true); // load SimpleXML
$current = $objDOM->xpath('picture');
function sort_current($t1, $t2) {
 return strcmp($t2['id'], $t1['id']); // to sort high > low
 }
usort($current, 'sort_current');

How come I am getting an output like this:

Array ( [0] => SimpleXMLElement Object ( [0] => 9 ) [1] => SimpleXMLElement Object ( [0] => 8 ) [2] => SimpleXMLElement Object ( [0] => 6 ) [3] => SimpleXMLElement Object ( [0] => 5 ) [4] => SimpleXMLElement Object ( [0] => 4 ) [5] => SimpleXMLElement Object ( [0] => 3 ) [6] => SimpleXMLElement Object ( [0] => 2 ) [7] => SimpleXMLElement Object ( [0] => 15 ) [8] => SimpleXMLElement Object ( [0] => 1 ) [9] => SimpleXMLElement Object ( [0] => 0 ) )

I wanted to get an output such as this:

Array ( [0] => 8 [1] => 6 [2] => 5 [3] => 4 [4] => 3 [5] => 9 [6] => 2 [7] => 15 [8] => 1 [9] => 0 [10] => )

what do I need to change to get a cleaned up array as above without all the SimpleXMLElement gubbins? Cheers, Andy

1 Answer 1

2

SimpleXML returns objects not arrays. You have to convert it, like this guy did here. There are a plenty of these on that page.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.