Sorting an Array
I have an array like this:
Goal diff DESC
Anybody know how I would achieve this?
The final array might have 12/13/14 different entries in it rather than just the two shown.
This is really what databases are for, why do you have unsorted arrays this large?
If it must stay in an array, this algorithm is what I can give you off the top of my head (there are probably much more efficient ways of doing this):
Objective: To sort rows by points then for then goal:
1. Bubble sort by name
2. Split the array by name
3. Sort by for in each group
4. Split each of those arrays by for.
5. Sort by goals in each group.
6. Merge them back together.
Memory won't be an issue with only a few rows, but don't do this with hundreds of rows. This has potential to be a memory monster.
I didn't even think! The data has come from a database, and it should be sorted in the query - duh and thanks!
It happens, best of luck.
Ah, in fact that's no good come to think of it. I have a database which I retrieve data from, I then work on it (calculations and stuff) and store it in an array so I can easily pass it. Therefore I can't perform MySQL sorts on the data as the data is not ready to be sorted at that stage.
So, any idea's?
I think you can you this function
I see if could solve your next problem.
|All times are GMT. The time now is 10:25 PM.|
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0