我试图根据元素的值安排一个数组。这里是我的数组代码:
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编码器代码?请随意查看我的代码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