数组根据某个字段倒序

$array=array(
    0=>array(
        'id'=>1,
        'num1'=>-1,
        'num2'=>100
        ),
    
    1=>array(
        'id'=>2,
        'num1'=>4,
        'num2'=>50
        ),
    2=>array(
        'id'=>3,
        'num1'=>900,
        'num2'=>800
        ),
    3=>array(
        'id'=>4,
        'num1'=>-16,
        'num2'=>-15
    )
);
//主要
foreach ($array as $key=>$value){
    $cha[$key] = $value['num2']-$value['num1'];
}
array_multisort($cha,SORT_STRING,SORT_DESC,$array);
//
echo '
';
print_r($array);
echo '';

 

posted @ 2015-08-19 17:09  浮夸浮华  阅读(380)  评论(0编辑  收藏  举报