Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

Possible Duplicate:
PHP - sort an array based on another array?

Need some help regarding array sorting....

I have two arrays. The main one (where the key is the user id) :

$user[31] = 'Tom'

$user[43] = 'Jane'

and another array with the order they should be displayed (where key is the order and value is the user id) :

$order[1] = 43

$order[2] = 31

How can I apply the ordering to the main array using the ordering one?

Thanks guys!

share|improve this question

marked as duplicate by Gumbo Apr 23 '10 at 14:34

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
@Fearghal: Thanks for the hint in the comments to my answer. I closed you question since it’s obviously a duplicate. – Gumbo Apr 23 '10 at 14:35

Use the keys in $order to select the users from $user in the right order:

$orderedUsers = array();
foreach ($order as $key) {
    $orderedUsers[] = $user[$key];
}
share|improve this answer
    
got the answer right here: stackoverflow.com/questions/348410/… – Fearghal Apr 23 '10 at 11:39

Use this one, it is usefull for your problem

$array = array("size" => "XL", "color" => "gold");
print_r(array_values($array));

Result as :

Array
(
    [0] => XL
    [1] => gold
) 
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.