排序多维数组 [英] sorting a multi-dimensional array
本文介绍了排序多维数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果之前已经回答了这个问题,我真的很抱歉,但这是我的问题
我有这个:
I'm really sorry if this has been answered before, but here is my problem
I have this:
array (size=256)
0 =>
array (size=2)<br>
0 => string 'name_a'
1 => string '2175'
1 =>
array (size=2)
0 => string 'name_d'
1 => string '1'
2 =><
array (size=2)
0 => string 'name_c'
1 => string '715'
3 =>
array (size=2)
0 => string 'name_b'
1 => string '5'
如果我为每个名称添加更多信息(例如时间值),我希望能够按从最大到最小或/和名称的数字对其进行排序.它的数组很大(我认为超过400个),我需要从上到下逐一显示它.如果有人有任何想法,我很想听听他们的想法!
And I want to be able to sort it by the number from most to least or/and name and if I add more info for each name such as time value. Its a huge array(over 400 I think) and I need to display it one by one, from top to bottom. If anyone have any ideas, I'd love to hear them!
推荐答案
使用 usort
就像这样:
Use usort
like so:
function myComp($a, $b) {
if($a[1] == $b[1]) {
return 0;
}
return ($a[1] > $b[1]) ? -1 : 1;
}
usort($myArray, 'myComp');
这篇关于排序多维数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文