tags:

views:

59

answers:

4

Hello All i want to sort the array in the way that

ASC order of user id

there is array like $user

i want to sort on the base

id $user['role'] =1;

then that element will set at the top of the array

+2  A: 

Look in the PHP manual at asort, sort, and ksort. I'm not exactly sure what you're asking, but one of them is bound to do what you need.

Rob
And if these don't then usort will, provided you write a correct callback function.
wimvds
This is very use full
Rajendra Banker
A: 

Does that information come from a database? In that case, doing something like ORDER BY role DESC, user_id would be better than having PHP sort it for you.

Daniel Egeberg
A: 

If your array example $user['role'] = 1 means that 1 is the user id you want to use sort($user); however if role is going to be numeric you would want asort($user); instead as sort will overwrite numeric keys. As @Rob above said you may want to use ksort but only if you are making the array $user[user_id] = role.

Hope this helps

Regards

Luke

Luke
A: 

Thanx All For Replying on my question

i got the solution here it is

function compare($a,$b) {return strcmp($a["role"]['ID'],$b["role"]['ID']);} usort($a,compare);

Keep In Touch...

Rajendra Banker