日期:2014-05-17  浏览次数:20637 次

实现排行版带有趋势的
实现排行版带有趋势的,该怎么实现呢?

------解决方案--------------------
//先变形为这样,即用 uid 做键。生成这些数据时就应该这样做好
$old_rank = array(
  132=>array('uid'=>132,'use_score'=>61570),
  121=>array('uid'=>121,'use_score'=>50932),
  145=>array('uid'=>145,'use_score'=>46789),
  100=>array('uid'=>100,'use_score'=>39089),
  167=>array('uid'=>167,'use_score'=>29089)
);
$new_rank = array(
  132=>array('uid'=>132,'use_score'=>61570),
  145=>array('uid'=>145,'use_score'=>51932),
  121=>array('uid'=>121,'use_score'=>50932),
  167=>array('uid'=>167,'use_score'=>40089),
  100=>array('uid'=>100,'use_score'=>39089)
);
foreach($new_rank as $k=>$v)
  $res[$k] = $v['use_score'] - $old_rank[$k]['use_score'];
print_r($res);
Array
(
    [132] => 0
    [145] => 5143
    [121] => 0
    [167] => 11000
    [100] => 0
)