I have been battling out with a bit of a complex ranking system.The ranking depend on students points which are independent of marks. The point calculation is okay with me. The problem comes in when breaking ties because that depends on student marks which is a different entity altogether. Students can have similar points but differ in marks which can be used to break a tie in case some students tie on points. I need help because i got stuck. Please refer to my picture to get a rough idea and tell me if it can be done. I have also included some of my code.
<?php
$rank_by_point=array();
//loop out students and get their admission number from which you calculate individual points based on an algorithm
foreach($students as $student => $student_no){
array_push($rank_by_point[$student_no],calculatePoints($student_no));
}
//sorting the points from highest to lowest
arsort($rank_by_point);
//the ranking code down here
$ties=array();
$break=array();
$initial_positions=array();
$rank = 0;
$last = false;
foreach($rank_by_point as $key => $value){
if($last != $value){
$last = $value;
$rank++;
}else{
//when a tie is detected add the values to a tie array
array_push($ties[$key],$rank);
}
array_push($initial_positions[$key],$rank);
}
//spliting of ties is done by getting marks and rearrangin the tie
foreach($ties as $admno => $st_rank){
$read_position=$rank;//same value for all keys in the ties array
$getmarks=getMarks($admno);
array_push($break[$admno],$getmarks);
//reorder the array in desc order
arsort($break);
}
//reranking the ties. i got stuck here :-(
?>
Add student marks as a smaller score into calculatePoints($student_no)
. e.g.
function calculatePoints($student_no){
/*add this before return it*/
$point = $point*1000;//make sure the new $point be bigger than the max $student_mark
$point += $student_mark;
return $point;
}
sort as you did now