这是我的代码。
<?php
$data['test1'][0] = array('total' => 67, 'edition' => 2, 'pkg_version' => "2.5.0" );
$data['test1'][1] = array('total' => 67, 'edition' => 2, 'pkg_version' => "0.1.0" );
$data['test1'][2] = array('total' => 67, 'edition' => 2, 'pkg_version' => "0.3.0" );
$data['test2'][0] = array('total' => 86, 'edition' => 1, 'pkg_version' => "1.5.0");
$data['test2'][1] = array('total' => 85, 'edition' => 6, 'pkg_version' => "0.53.0");
$data['test2'][2] = array('total' => 98, 'edition' => 2, 'pkg_version' => "0.3");
$data['test2'][3] = array('total' => 98, 'edition' => 2, 'pkg_version' => "0.2");
$data['test3'][0] = array('total' => 60, 'edition' => 6, 'pkg_version' => "0.3");
$data['test3'][1] = array('total' => 60, 'edition' => 7, 'pkg_version' => "0.1.1");
$data['test3'][2] = array('total' => 60, 'edition' => 7, 'pkg_version' => "0.25");
foreach ($data as $row) {
foreach ($row as $k){
foreach ($k as $key => $value){
${$key}[] = $value;
}
}
}
array_multisort($pkg_version, SORT_DESC, $data);
echo "<pre>";
print_r($data);
echo "</pre>";
?>
我正在尝试使用 array_multisort 函数对多维数组进行排序
我想对要订购的每个元素的 pkg_version 进行排序
退回的订单不符合预期。不确定,我误解了如何
array_multisort 有效吗?或者我的代码是错误的。你们能帮我吗?我试着
解决这个问题很久了。这是一个相当复杂的维度数组。
这是运行上面代码后的结果。
Array
(
[test1] => Array
(
[0] => Array
(
[total] => 67
[edition] => 2
[pkg_version] => 2.5.0
)
[1] => Array
(
[toal] => 67
[edition] => 2
[pkg_version] => 0.1.0
)
[2] => Array
(
[total] => 67
[edition] => 2
[pkg_version] => 0.3.0
)
)
[test2] => Array
(
[0] => Array
(
[total] => 86
[edition] => 1
[pkg_version] => 1.5.0
)
)
四季花海