我正在尝试根据元素的值安排一个数组。无论如何,这是我的数组代码:
array (
[0] => array (
[id] => 5
[title] => yesyes3
[msg] => yes yes yes yes
[date] => 2016-06-05
[match] => 1
)
[1] => array (
[id] => 4
[title] => yes2
[msg] => yes yes yes
[date] => 2016-06-04
[match] => 4
)
[2] => array (
[id] => 1
[title] => test1
[msg] => yes
[date] => 2016-06-01
[match] => 2
)
[3] => array (
[id] => 3
[title] => test2
[msg] => no
[date] => 2016-06-03
[match] => 1
)
[4] => array (
[id] => 2
[title] => yes1
[msg] => no
[date] => 2016-06-02
[match] => 6
)
)
我有什么办法可以根据比赛安排他们,看起来会像这样吗?
array (
[0] => array (
[id] => 2
[title] => yes1
[msg] => no
[date] => 2016-06-02
[match] => 6
)
[1] => array (
[id] => 4
[title] => yes2
[msg] => yes yes yes
[date] => 2016-06-04
[match] => 4
)
[2] => array (
[id] => 1
[title] => test1
[msg] => yes
[date] => 2016-06-01
[match] => 2
)
[3] => array (
[id] => 3
[title] => test2
[msg] => no
[date] => 2016-06-03
[match] => 1
)
[4] => array (
[id] => 5
[title] => yesyes3
[msg] => yes yes yes yes
[date] => 2016-06-05
[match] => 1
)
)
是否有任何php codeigniter代码?请随时在这里检查我的代码https://eval.in/599473
谢谢!
您可以使用简单的PHP代码实现目标:
usort($array, function ($one, $two) {
if ($one['match'] === $two['match']) {
return 0;
}
return $one['match'] > $two['match'] ? -1 : 1;
});
参考:usort
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句