This is supposed to be a simple thing turned complicated. I got a multi array:
$members_list[key, array]
ie:
$members_list[0, ['a' => 1; 'b' => 'name']]
$members_list[88, ['a' => 1; 'b' => 'name']]
$members_list[25, ['a' => 1; 'b' => 'name']]
$members_list[0, ['a' => 1; 'b' => 'name']]
All i'm trying to do it organize the $members_list by the key using ksort.
ksort($members_list);
But it doesn't. for some reason it just doesn't sort anything at all. The data is pulled from a mysql db, and put into the array which is $members_list's value.
IF is key($members_list) it ill turn up to be the 0,88,25,0,... so why isn't it sorting.
I first thought it to be a string so i intval() to make sure. Then i even tried adding that key to the ['sort' => 0, 'a' => 1, 'b' => 'name'] but the result is the same: nothing.
I'm using each members calculated % so i have mixed numbers. Just wondering what was your thoughts on this. I'm sure i'm doing something wrong just can't figure it out.
Thanks for your help.
Sorting a multiarray
Moderator: General Moderators
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Sorting a multiarray
If it is pulled from a database why not just sort it in the database? That is what it is designed for! 
Re: Sorting a multiarray
Because i'm calculating the percentages outside with the data from the db those are not pulled from the DB. Should've mentioned that, sorry. But that would be too easy 
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Sorting a multiarray
You can still do percentages in sql. Look into it it might make your life easier. Just a thought!
Re: Sorting a multiarray
Yes but that would mean rewriting a lot of code, i was looking into a simpler solution, since ksort it theory does what i want, i was looking for someone with knowledge into array sorting that could help me fill in the gaps, or shed some light on my problem.
But thanks for your point, it will be an alternative if i can't get anyone to help explain array sorting.
But thanks for your point, it will be an alternative if i can't get anyone to help explain array sorting.
- jaoudestudios
- DevNet Resident
- Posts: 1483
- Joined: Wed Jun 18, 2008 8:32 am
- Location: Surrey
Re: Sorting a multiarray
It should not be a lot of code, actually probably less than the amount of php you will need. I appreciate you might be more familiar with php so want to avoid the sql calculation route, but it would probably be much more efficient to do it in sql.
Just a though.
In regards to your array it is sorting it!
Read... http://uk2.php.net/ksort, let me know if dont see the issue.
Just a though.
In regards to your array it is sorting it!
Read... http://uk2.php.net/ksort, let me know if dont see the issue.