Hello All i want to sort the array in the way that
ASC order of user id
there is array like $use开发者_Python百科r
i want to sort on the base
id $user['role'] =1;
then that element will set at the top of the array
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.
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.
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
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);
精彩评论