【发布时间】:2013-06-24 15:43:05
【问题描述】:
好的,我已经在 stackoverflow 中得到了这个问题,但遗憾的是它在 javascript 中 - Javascript - sort array based on another array
我想要它在 PHP 中
$data = array(
"item1"=>"1",
"item2"=>"3",
"item3"=>"5",
"item4"=>"2",
"item5"=>"4"
);
要匹配这个数组的排列:
sortingArr = array("5","4","3","2","1");
以及我正在寻找的输出:
$data = array(
"item3"=>"5",
"item5"=>"4",
"item2"=>"3",
"item4"=>"2",
"item1"=>"1"
);
知道如何做到这一点吗? 谢谢。
【问题讨论】:
-
你可以
asort()他们俩。 -
使用
usort(),具有比较$sortingArr中值位置的比较函数。