多维数组按字符串排序 [英] multi dimensional array sorting by string
本文介绍了多维数组按字符串排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要弄清楚如何正确地做到这一点,我有这个多维数组:
I'm breaking my head trying to figure out how to do this right, I have this multi dimensional array:
Array
(
[0] => Array
(
[time] => November 1st 10:10
[query] => movies
[set] => 1
[matches] => No matching results
[results] => 5
)
[1] => Array
(
[time] => November 1st 10:10
[query] => cinemas
[set] => 1
[matches] => No matching results
[results] => 2
)
)
在现实生活中,可能会有更多的子数组,但是有人说我想按字母查询"对它进行排序,我该如何实现呢?
In real life, there could be alot more sub-arrays, but et's say I want to sort it by "query" alphabetically, how can I achieve this?
我只看到整数类型或键索引的解决方案,在这种情况下,最终结果将是:
I saw only solutions for integer type or key index, the end result, in this case, would be:
Array
(
[0] => Array
(
[time] => November 1st 10:10
[query] => cinemas
[set] => 1
[matches] => No matching results
[results] => 2
)
[1] => Array
(
[time] => November 1st 10:10
[query] => movies
[set] => 1
[matches] => No matching results
[results] => 5
)
)
非常感谢,谢谢.
推荐答案
function querySort ($x, $y) {
return strcasecmp($x['query'], $y['query']);
}
usort($myArray, 'querySort');
这篇关于多维数组按字符串排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文