我正在尝试使用 array_multisort 函数对多维数组进行排序
我期待多维数组使用 $sort 中的值对自身进行排序。$sort 与我的多维数组的体积元素有关。
我希望名称元素按以下顺序排列:
'名字' => 8, '名字' => 6, '名字' => 7, '名字' => 9', '名字' => 10, '名字' => 10,
退回的订单与预期不符。也许我误解了 array_multisort 的工作原理?
Array
(
[test1] => Array
(
[volume] => 67
[edition] => 2
[name] => 6
[num] => 2
)
[test2] => Array
(
[volume] => 86
[edition] => 1
[name] => 7
[type] => 2
)
[test3] => Array
(
[volume] => 85
[edition] => 6
[name] => 8
[type] => 2
)
[test4] => Array
(
[volume] => 98
[edition] => 2
[name] => 9
[type] => 2
)
[test5] => Array
(
[volume] => 86
[edition] => 6
[name] => 10
[type] => 2
)
[test6] => Array
(
[volume] => 67
[edition] => 7
[name] => 11
[type] => 2
)
)
$sort = array(85, 67, 86, 98, 86, 67);
array_multisort($sort, $data);
这是原始数组:
$data['test1'] = array('volume' => 67, 'edition' => 2, 'name' => 6, 'num' => 2,);
$data['test2'] = array('volume' => 86, 'edition' => 1, 'name' => 7, 'type' => 2,);
$data['test3'] = array('volume' => 85, 'edition' => 6, 'name' => 8, 'type' => 2,);
$data['test4'] = array('volume' => 98, 'edition' => 2, 'name' => 9, 'type' => 2,);
$data['test5'] = array('volume' => 86, 'edition' => 6, 'name' => 10, 'type' => 2,);
$data['test6'] = array('volume' => 67, 'edition' => 7, 'name' => 11, 'type' => 2,);