Jon Bennett wrote:
hi, I have the following array, which I need to sort by quantity... Array ( [2408] => Array ( [name] => Havaianas Top Pink Crystal [size] => 5 (37/38) [quantity] => 4 ) [3388] => Array ( [name] => Havaianas Brazil Silver [size] => 6/7 (39/40) [quantity] => 6 ) [2666] => Array ( [name] => Havaianas Brasil Black [size] => 8/9 (41/42) [quantity] => 1 ) [3210] => Array ( [name] => Havaianas Margaridas Yellow [size] => 5 (37/38) [quantity] => 1 ) [2552] => Array ( [name] => Havaianas Flash White [size] => 5 (37/38) [quantity] => 1 ) ) I need to keep the indexes if poss. Many thanks, jon
This works for me: function cmp($a, $b) { $aq = $a['quantity']; $bq = $b['quantity']; if ($a == $b) { return 0; } return ($aq < $bq) ? -1 : 1; } uasort($data, "cmp"); To reverse the sort order: return ($aq > $bq) ? -1 : 1; -- _____________________ Myron Turner http://www.room535.org http://www.bstatzero.org http://www.mturner.org/XML_PullParser/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php