Home >Backend Development >PHP Tutorial >能否根据下面的两个数组来判断趋势?
php
$old_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>121,'use_score'=>50932), "3"=>array('uid'=>145,'use_score'=>46789), "4"=>array('uid'=>100,'use_score'=>39089), "5"=>array('uid'=>167,'use_score'=>29089) ); $new_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>145,'use_score'=>51932), "3"=>array('uid'=>121,'use_score'=>50932), "4"=>array('uid'=>167,'use_score'=>40089), "5"=>array('uid'=>100,'use_score'=>39089) );
$old_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>121,'use_score'=>50932), "3"=>array('uid'=>145,'use_score'=>46789), "4"=>array('uid'=>100,'use_score'=>39089), "5"=>array('uid'=>167,'use_score'=>29089));$new_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>145,'use_score'=>51932), "3"=>array('uid'=>121,'use_score'=>50932), "4"=>array('uid'=>167,'use_score'=>40089), "5"=>array('uid'=>100,'use_score'=>39089));foreach($old_rank as $k=>$v) $old[$v['uid']] = $k;foreach($new_rank as $k=>$v) $new[$v['uid']] = $k;foreach($new as $k=>$v) echo "$k 排名 $v " . ($v - $old[$k]) . '<br>';132 排名 1 0
$old_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>121,'use_score'=>50932), "3"=>array('uid'=>145,'use_score'=>46789), "4"=>array('uid'=>100,'use_score'=>39089), "5"=>array('uid'=>167,'use_score'=>29089));$new_rank = array( "1"=>array('uid'=>132,'use_score'=>61570), "2"=>array('uid'=>145,'use_score'=>51932), "3"=>array('uid'=>121,'use_score'=>50932), "4"=>array('uid'=>167,'use_score'=>40089), "5"=>array('uid'=>100,'use_score'=>39089));foreach($old_rank as $k=>$v) $old[$v['uid']] = $k;foreach($new_rank as $k=>$v) $new[$v['uid']] = $k;foreach($new as $k=>$v) echo "$k 排名 $v " . ($v - $old[$k]) . '<br>';132 排名 1 0