我有一个看起来像这样的数组:
array(
(int) 0 => array(
'SomeItem' => array(
'id' => '1',
'number' => '3',
'created' => '2012-07-20 23:34:00',
'modified' => '2012-07-20 23:34:00'
)
)
(int) 1 => array(
'SomeItem' => array(
'id' => '1',
'number' => '6',
'created' => '2012-07-20 23:34:00',
'modified' => '2012-07-20 23:34:00'
)
)
)
我如何按“数字”对其进行排序,这样我可以按照数字的升序排序,同时仍保持结构?
谢谢!
答案 0 :(得分:1)
使用关闭:
usort($array, function($a, $b)
{
if ($a['SomeItem']['number'] == $b['SomeItem']['number'])
return 0;
return ($a['SomeItem']['number'] < $b['SomeItem']['number']) ? -1 : 1;
}
);
没有
function cmp($a, $b)
{
if ($a['SomeItem']['number'] == $b['SomeItem']['number'])
return 0;
return ($a['SomeItem']['number'] < $b['SomeItem']['number']) ? -1 : 1;
}
usort($array, 'cmp');