Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to sort $ar1 by the descending order values of $ar2. Nothing is happening.

    $ar1 = array($arperc);
        $ar2 = array($arid);
        array_multisort($ar1,$ar2);


print_r($ar1);

What am I missing

share|improve this question
2  
Could you give us examples for the values of $arperc and $arid? –  Justin Lucas Dec 7 '11 at 21:53
    
your arguments are the wrong way around :D –  tomwilde Dec 7 '11 at 21:54
1  
You really need to provide some example data to allow us to solve that.. But it seems that you send in an array with just one value? You probably want to just create a copy with $ar1 = $arperc; if you don't want to sort the original array. –  fiskfisk Dec 7 '11 at 21:54
add comment

1 Answer

up vote 1 down vote accepted

If you want to use the elements of $ar2 as sorting keys, you need to change the order of arguments to array_multisort:

array_multisort($ar2, $ar1);

This will sort $ar2 in ascending order, and also change the order of $ar1 elements exactly as the order of $ar2 is changed by the sorting. To change the order to descending:

array_multisort($ar2, SORT_DESC, $ar1);
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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