$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
SimpleXML returns objects not arrays. You have to convert it, like this guy did here. There are a plenty of these on that page.