数组PHP数组排序 [英] PHP sort an array of array
本文介绍了数组PHP数组排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有folloring阵列结构:
I have the folloring array structure:
$list = array();
$element1 = array('start' => '10', 'end' => '15');
$element2 = array('start' => '1', 'end' => '5');
$list[] = $element1;
$list[] = $element2;
在的每一个元素开始
和结束
是数字而已。
我要排序 $列表
按启动
值。我怎样才能做到这一点用途不同?
I would like to sort $list
by start
values. How can I do that effectivly?
推荐答案
您可以使用 usort
与此相比功能:
You can use usort
with this comparison function:
function cmp($a, $b) {
if ($a['start'] == $b['start']) {
return $a['end'] - $b['end'];
} else {
return $a['start'] - $b['start'];
}
}
通过这种比较功能的元素被下令将他们的启动的值,然后再由他们的结束的值。
With this comparison function the elements are ordered by their start value first and then by their end value.
这篇关于数组PHP数组排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文