Sort XML Data
Posted: Thu Jan 24, 2008 8:12 pm
I've been playing around with SimpleXMLElement to parse XML document, and I've been trying to sort the data by one if its elements. My code does just that, but I was wondering if is a efficient / elegant implementation.
Thanks.
Code: Select all
<?php
$xml = new SimpleXMLElement($xmlstr);
$i = 0;
foreach ($xml->PLAYERLIST->PLAYER as $player) {
$var[$i] = (int)$player->PLAYERKILLS;
$i++;
}
sort($var);
$i = 0;
foreach ($var as $key => $val) {
$sorted[$i] = $val;
$i++;
}
print_r(array_reverse($sorted));
?>