0
考虑以下数组:排序PHP数组由其他数组
$array = array(
'note' => array('test', 'test1', 'test2', 'test3', 'test4'),
'year' => array('2011','2010', '2012', '2009', '2010'),
'type' => array('journal', 'conference', 'editorial', 'conference','conference'),
);
阵列可如果是比较容易使用下面的函数很容易地转化:
for($i=0; $i < count($array['type']); $i++)
foreach($array as $key=> $value)
$temp[$i][$key] = $value[$i];
print_r($temp);
我想对它进行排序使用以下标准:
- 阵列
- 在对类别进行排序后,我想按每个类别排序
year DESC
。
期望的结果:
Array
(
[note] => Array
(
[0] => test
[1] => test2
[2] => test1
[3] => test4
[4] => test3
)
[year] => Array
(
[0] => 2011
[1] => 2012
[2] => 2010
[3] => 2010
[4] => 2009
)
[type] => Array
(
[0] => journal
[1] => editorial
[2] => conference
[3] => conference
[4] => conference
)
)
这不是分组相关内容的一个好办法。 –
这似乎是你通过将这些东西存储在一个二维数组中而使它变得不必要的困难。 – Daniel
那么这是不可能做到这一点?因为我发现每个使用PHP排序函数的解决方案(它们都使用快速排序),因此返回正确结果是不可能的。 – glarkou