Add and find the rank in array using php
Hi Recently i went to interview i was asked to add a mark and find the rank of it using php. 1) First i created a function called rankChecker and passing two parameter like collection of marks in array and mark that will be added and finding the rank of it. 2) Then i created dumpy variable $s ,$ab as array. 3)After that i added the mark in the array mark list and sorted into descending order and looped in for loop. 4) passing the value of first array into dumpy array $ab as key and passing the $i value incremented by one as $i starts with zero. 5) And returning the current $ab array and passing $mark as key value in it. function rankChecker($arr,$mark){ $arr[] = $mark; rsort($arr); $ab = array(); //echo count($arr); for($i=0;$i<count($arr);$i++){ $ab[$arr[$i]] = $i+1; } return $ab[$mark]; } $arr=[39,37,34,56,67,23,37]; $mark=10; print_r(rankChecker($arr,$ mark));