ReJoshua Posted February 21, 2011 Share Posted February 21, 2011 Generally I am able to help my self on the forums. But, this one has me stumped. I've done it before and I don't remember it being this hard. The array looks something like so $users['id'] = '00001','00002','0003' $users['jobs'] = '22','322','112' $users['connected'] = '12','210','89' $users['percent'] = '54','65','89' I've used so much different things to try and take those, keep the data together (index 0 might be moved to 2, but all values from 0 are moved to 2) and sort by 'percent'. So I can display the person that has the highest percentage first. Basically the data was originally a CSV that is now in a database and is pulled, percentages calculated and then displayed. But the order is off. There is a bunch more data then show but I'm using PHP to do all the math for adding up jobs, seeing whats connected right and then coming up with a percentage, sticking it all in an array so I can sort it; but for some reason I cannot remember how I've done this before. Quote Link to comment Share on other sites More sharing options...
requinix Posted February 21, 2011 Share Posted February 21, 2011 Looking for array_multisort? Quote Link to comment Share on other sites More sharing options...
ReJoshua Posted February 21, 2011 Author Share Posted February 21, 2011 It kind of worked. Put everything out of order. IE just reordered the 'percent' column and left the others where they were (which is by default 'id'). But I figured out how to do it using that and some other code. Here is the below code I found and made it work perfectly. Thanks for the direction, helped a bunch. $sort_direction = 'SORT_DESC'; $sort_field = 'percent'; $sort_arr = array(); foreach($users AS $uniqid => $row){ foreach($row AS $key=>$value){ $sort_arr[$key][$uniqid] = $value; } } array_multisort($sort_arr[$sort_field], constant($sort_direction), $users); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.