Creating and ordering an array before looping through it



I am needing to create an array from an XML response and then order by a field that is in that XML.


I have parsed the XML fine and ended up with 3 values that I need in my foreach loop.



$optionsArray = array();

foreach ($options as $key => $option) {
$price = $option->Price;
$shortDesc = $option->ShortDescription;
$longDesc = $option->LongDescription;

$optionsArray[] = array('shortdesc' => $shortDesc, 'longdesc' => $longDesc, 'price' => $price);
}


This works fine, but now I wish to order the array using the 'price' value (descending) and then I can show the items correctly.


I have looked into usort and arsort and all the others but cannot make sense. Any examples using my code for help?


Thanks.


No comments:

Post a Comment