时间:2021-07-01 10:21:17 帮助过:8人阅读
function cmp($a, $b){
if ($a["vote_num"] == $b["vote_num"]) {
return 0;
}
return ($a["vote_num"] > $b["vote_num"]) ? -1 : 1;
}
$arr = Array
(
0 => Array
(
o_id => 1861,
o_name => 2,
o_pic => 'http://g.jb51.net/image.gif' ,
o_detail => 人人,
vote_num => 1
),
1 => Array
(
o_id => 1844,
o_name => 芭比,
o_pic => 'http://upload.jb51.net/game_image/dfxxz/dfVIP.files/shenxiandao.jpg',
o_detail => 也是美女呢,
vote_num => 2
),
2 => Array
(
o_id => 1843,
o_name => 程程,
o_pic => 'http://g.jb51.net./upload_img/2011-06/31554_4d0088da7a61ad9c8c02a530be94d98e.png',
o_detail => 美女哦,
vote_num => 3
)
);
uasort($arr, ”cmp“);
echo ‘< pre style="text-align:left" >';
print_r ($arr);
echo ‘< / pre >';
返回
代码如下:
Array
(
[2] => Array
(
[o_id] => 1843
[o_name] => 程程
[o_pic] => http://g.jb51.net./upload_img/2011-06/31554_4d0088da7a61ad9c8c02a530be94d98e.png
[o_detail] => 美女哦
[vote_num] => 3
)
[1] => Array
(
[o_id] => 1844
[o_name] => 芭比
[o_pic] => http://upload.jb51.net/game_image/dfxxz/dfVIP.files/shenxiandao.jpg
[o_detail] => 也是美女呢
[vote_num] => 2
)
[0] => Array
(
[o_id] => 1861
[o_name] => 2
[o_pic] => http://g.jb51.net/image.gif
[o_detail] => 人人
[vote_num] => 1
)
)
http://www.bkjia.com/PHPjc/326033.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/326033.htmlTechArticle如果值没有重复的情况,可以先用array_flip()来交换键和值,然后krsort(),最后再array_flip()交换回来,就可以比较大小了。如果要截取数组,可...