function sort($oba, $obb){ //如果是对象 if($oba->grade < $obb->grade){ return 1; }elseif ($oba->grade == $obb->grade){ return ($oba->during <= $obb->during) ? 1 : -1; } //如果是数组 //if($oba['grade'] < $obb['grade']){ // return 1; //}elseif ($oba['grade'] == $obb['grade']){ // return ($oba['during'] <= $obb['during']) ? 1 : -1; //} } usort($info,'sort');
如果是在框架中使用(使用匿名函数操作)
usort($datas,function($oba,$obb){ if($oba['is_checkin'] < $obb['is_checkin']){ return 1; }elseif ($oba['is_checkin'] == $obb['is_checkin']){ return ($oba['is_checkin'] <= $obb['is_checkin']) ? 1 : -1; } });
排序后