我有数组以下药结构:PHP排序数组通过子数组值
Array
(
[0] => Array
(
[configuration_id] => 10
[id] => 1
[optionNumber] => 3
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
[1] => Array
(
[configuration_id] => 9
[id] => 1
[optionNumber] => 2
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
[2] => Array
(
[configuration_id] => 8
[id] => 1
[optionNumber] => 1
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
)
什么是订单的最佳途径阵列,基于该OPTIONNUMBER增量的方式?
所以结果如下:
Array
(
[0] => Array
(
[configuration_id] => 8
[id] => 1
[optionNumber] => 1
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
[1] => Array
(
[configuration_id] => 9
[id] => 1
[optionNumber] => 2
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
[2] => Array
(
[configuration_id] => 10
[id] => 1
[optionNumber] => 3
[optionActive] => 1
[lastUpdated] => 2010-03-17 15:44:12
)
)
并没有真正helpe我,usort需要我提供其使用的功能 - 这是比较麻烦的问题,我不能让我的头一轮 – Sjwdavies 2010-03-19 13:15:53
嗯,他刚才给你的功能使用。你将不得不接受,并不总是有一个内置的功能来做你想做的,你必须自己写。比较函数只需要返回1,0或-1,表示两个元素的排序顺序。 – Tesserex 2010-03-19 13:19:08
我进一步研究了usort,它确实很酷。 我写了一个简单的比较函数,但是错过了'=='。 感谢您的帮助 – Sjwdavies 2010-03-19 13:38:09