phprookie72 Posted November 9, 2010 Share Posted November 9, 2010 I have an array as follow $data=array('team1'=>array('w'=>0,'l'=>1,'t'=>0,'pts'=>0', team2'=>array('w'=>1,'l'=>0,'t'=>0,'pts'=>3), 'team3'=>array('w'=>0,'l'=>0,'t'=>1,'pts'=>1) ) I would like to sort the data useing pts key in descending order, how would i go about doing that? thanks. Link to comment https://forums.phpfreaks.com/topic/218172-sort-2dimension-array-with-associative-key/ Share on other sites More sharing options...
sasa Posted November 9, 2010 Share Posted November 9, 2010 <?php $data=array('team1'=>array('w'=>0,'l'=>1,'t'=>0,'pts'=>0), 'team2'=>array('w'=>1,'l'=>0,'t'=>0,'pts'=>3), 'team3'=>array('w'=>0,'l'=>0,'t'=>1,'pts'=>1) ); foreach ($data as $team => $value) $tmp[] = $value['pts']; array_multisort($data, SORT_DESC, SORT_NUMERIC, $tmp, SORT_DESC, SORT_NUMERIC); print_r($data); ?> Link to comment https://forums.phpfreaks.com/topic/218172-sort-2dimension-array-with-associative-key/#findComment-1132159 Share on other sites More sharing options...
phprookie72 Posted November 9, 2010 Author Share Posted November 9, 2010 sweet thank you Link to comment https://forums.phpfreaks.com/topic/218172-sort-2dimension-array-with-associative-key/#findComment-1132190 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.