title: Assign the same rank to student with the same scores
body: <p>I'm assigning ranks to students based on their scores but I encountered a problem where if two or more students have the same scores they are given different ranks.</p>
  <p>E.G John, Rita, and Mary scored 76. John is 1st, Rita is 2nd, and Mary is 3rd.</p>
  <ol>
  <li>John ==&gt; 76</li>
  <li>Rita ==&gt; 76</li>
  <li>Mary ==&gt; 76</li>
  <li>Bukky ==&gt;74</li>
  </ol>
  <p>I want three of them to have the rank as 1st.</p>
  <ol>
  <li>John ==&gt; 76</li>
  <li>Rita ==&gt; 76</li>
  <li>Mary ==&gt; 76</li>
  <li>Bukky ==&gt;74</li>
  </ol>
  <pre class="lang-php prettyprint-override"><code>public function getStudentpositionOnlyClass($student_id, $class_id, $terms)
  {
      $array_product = array();
  
      if ($class_id == 22 || $class_id == 23) {
          if ($terms == 'f') {
              $totField = 'ft_tot_score';
              $table = 'ftscores_rn';
          } elseif ($terms == 'm') {
              $totField = 'mt_tot_score';
              $table = 'mtscores_rn';
          } elseif ($terms == 's') {
              $totField = 'tot_score';
              $table = 'scores_rn';
          } elseif ($terms == 'h') {
              $totField = 'h_tot_score';
              $table = 'hscores_rn';
          }
      } else {
          if ($terms == 'f') {
              $totField = 'ft_tot_score';
              $table = 'ftscores_primary';
          } elseif ($terms == 'm') {
              $totField = 'mt_tot_score';
              $table = 'mtscores_primary';
          } elseif ($terms == 's') {
              $totField = 'tot_score';
              $table = 'scores_primary';
          } elseif ($terms == 'h') {
              $totField = 'h_tot_score';
              $table = 'hscores_primary';
          }
      }
  
      $fail = 0;
      $pass = 0;
  
      $resultlist = $this-&gt;student_model-&gt;fullSearchByClass($class_id);
  
      foreach ($resultlist-&gt;result_array() as $key =&gt; $stdName) {
          $idd = $key + 1;
          $mId[$idd] = $stdName['pstudent_id'];
  
          $totalSubMarks = $this-&gt;db-&gt;query(
              &quot;SELECT  mts.subject_id
                       FROM &quot; . $table . &quot; mts
                       LEFT JOIN subjects sub ON(sub.id=mts.subject_id)
                       WHERE class_id=&quot; . $class_id .
              &quot; AND mts.subject_id IS NOT NULL
                       GROUP BY mts.subject_id ORDER BY sub.name&quot;);
          $gtotal = 0;
          $totSubjects = 0;
  
          foreach ($totalSubMarks-&gt;result_array() as $tmrow) {
  
              $totalMarks = $this-&gt;student_model-&gt;getTotalMarksForStudnets($tmrow['subject_id'],
                  $stdName['pstudent_id'], $table, $totField);
              // //// set mtotalmark
  
              $gtotal = $gtotal + $totalMarks;
              // //// set mgtotal
              $mGTotal[$idd] = $gtotal;
  
              if ($totalMarks != 0) {
                  $totSubjects = $totSubjects + 1;
              }
              // //// set mAvg
              if ($totSubjects != 0) {
                  $mAvg[$idd] = round($gtotal / $totSubjects, 1);
              } else {
                  $mAvg[$idd] = 0;
              }
          }
  
          // /////////
          if ($totSubjects != 0) {
              $percentage = ($gtotal / $totSubjects);
          }
          if ($percentage &gt;= 0 &amp;&amp; $percentage &lt;= 39.99) {
              $fail = $fail + 1;
          } else {
              $pass = $pass + 1;
          }
      }
  
      foreach ($mAvg as $dd =&gt; $val) {
          // if pure numbers store in nums array
          if (! is_nan($val)) {
              $nums[$dd] = $val;
          }
      }
      arsort($nums);
  
      $id = 1;
      foreach ($nums as $kk =&gt; $av) {
  
          foreach ($totalSubMarks-&gt;result_array() as $tmrow) {
              $totalMarks = $this-&gt;student_model-&gt;getTotalMarksForStudnets($tmrow['subject_id'], $mId[$kk], $table,
                  $totField);
          }
  
          if ($student_id == $mId[$kk]) {
              return $id;
          }
          // $array_product['student'.$mId[$kk]]= $id;
          $id += 1;
      }
  }
  </code></pre>