如何对数组进行排序 [英] How to sort an array
本文介绍了如何对数组进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Array
(
[0] => stdClass Object
(
[posts] => 29
[term_id] => 49
)
[1] => stdClass Object
(
[posts] => 2
[term_id] => 54
)
[2] => stdClass Object
(
[posts] => 11
[term_id] => 36
)
)
如何按照帖子排序这个数组?
喜欢2,11,29
我的尝试:
How I can sort this array by no of posts?
like 2,11,29
What I have tried:
function cmp($a, $b)
{
if ($a["posts"] == $b["posts"]) {
return 0;
}
return ($a["posts"] < $b["posts"]) ? -1 : 1;
}
usort ($array_o, "cmp");
推荐答案
a,
b)
{
< span class =code-keyword> if (
a [ 帖子] ==
这篇关于如何对数组进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文