我有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.