PHP - 如何按值对2个变量进行排序?

I wanna sort this 2 variables by the variable 'wons'

I mean, I first wanna sort the variable 'wons' and I want the respective 'final' like:

$final[0] = 'pinco'; 
$final[1] = 'pallino';

$wons[0] = 3; 
$wons[1] = 7;

Now i want to sort this 2 variables for 'wons' variable like I want this result:

I want the first result to be pallino and the score 7 and etc..

Can anyone help me? I have tried so hard.. The language is PHP

The function you are looking for is called array_multisort

See: http://php.net/manual/en/function.array-multisort.php

The first example explains the same situation you are describing:

Example #1 Sorting multiple arrays

<?php
$ar1 = array(10, 100, 100, 0);
$ar2 = array(1, 3, 2, 4);
array_multisort($ar1, $ar2);

var_dump($ar1);
var_dump($ar2);
?>

In this example, after sorting, the first array will contain 0, 10, 100, 100. The second array will contain 4, 1, 2, 3. The entries in the second array corresponding to the identical entries in the first array (100 and 100) were sorted as well.

array(4) {
  [0]=> int(0)
  [1]=> int(10)
  [2]=> int(100)
  [3]=> int(100)
}
array(4) {
  [0]=> int(4)
  [1]=> int(1)
  [2]=> int(2)
  [3]=> int(3)
}

If you have both arrays in same order, then you can use arsort() for wons array . Then find corresponding element in the final array. Below code may help you

<?php
 $final  = array('0'=>'pinco','1'=>'pallino'); 
 $wons = array('0'=>3,'1'=>7);
 arsort($wons);
 foreach($wons as $key => $val)
 {
    echo $val.'-'.$final[$key].'<br>';
 }
?>