PHP-以相同方式对两个数组进行排序
我有两个不同的数组.一个数组,一个,用于列出人员.我的另一个数组b,用于列出他们的年龄.我按数字对b进行排序,然后将其反转以使其按降序排列.我已经做好了这一步.
I have two different arrays. One array, a, for a list of people. My other array, b, for a list of their ages. I go to sort b by number and then reverse it so it goes in descending order. I got to this part okay.
如何对(一个人的名字列表)进行排序,以便仍将相同的值与排序后的列表配对?
How do I sort a (a list of people's names) so that the same values are still paired up with the sorted list?
示例:
a分别包含Bob,Sue,Phil和Jenny
a contains Bob, Sue, Phil, and Jenny respectively
b分别包含15、12、13和13.
b contains 15, 12, 13, and 13 respectively.
我希望我的结果是:
a分别包含Bob,Jenny,Phil和Sue
a contains Bob, Jenny, Phil, and Sue respectively
b分别包含15、13、13和12
b contains 15, 13, 13, and 12 respectively
http://php.net/manual/zh-CN/function.array-multisort.php
在参考文献中使用示例1:
using example #1 in the reference:
$a = array('Bob', 'Sue', 'Phil', 'Jenny');
$b = array(15, 12, 13, 13);
array_multisort($a, $b);
print_r($a);
> Array
(
[0] => Bob
[1] => Jenny
[2] => Phil
[3] => Sue
)
print_r($b);
> Array
(
[0] => 15
[1] => 13
[2] => 13
[3] => 12
)