首页 > 解决方案 > 为每个 PHP 排序数据 - Codeigniter

问题描述

我在编码时遇到问题。我想将数据从较高值保存到较低值。例如:$nilai 值为 1,2,3,4,5。我需要来自较高价值 $nilai (5,4) 的 2 个数据。

任何解决方案?

这是我的代码:

public function savereport()
    {
        
        $fuzzyfikasi = $this->seleksi->getFuzzyfikasi();

        $maxC1 = $this->hitung->maxC1();
        $maxC2 = $this->hitung->maxC2();
        $maxC3 = $this->hitung->maxC3();
        $maxC4 = $this->hitung->maxC4();
        $maxC5 = $this->hitung->maxC5();

        $minC1 = $this->hitung->minC1();
        $minC2 = $this->hitung->minC2();
        $minC3 = $this->hitung->minC3();
        $minC4 = $this->hitung->minC4();
        $minC5 = $this->hitung->minC5();

        $bobotC1 = $this->hitung->bobotC1();
        $bobotC2 = $this->hitung->bobotC2();
        $bobotC3 = $this->hitung->bobotC3();
        $bobotC4 = $this->hitung->bobotC4();
        $bobotC5 = $this->hitung->bobotC5();
 
        $i = 1;
        foreach ($fuzzyfikasi as $f) :

         $i;
         $npm = $f['npm'];
         $rankC1 = ($f['C1'] / $maxC1['C1']) * $bobotC1['bobot'];
         $rankC2 = ($minC2['C2'] / $f['C2']) * $bobotC2['bobot'];
         $rankC3 = ($f['C3'] / $maxC3['C3']) * $bobotC3['bobot'];
         $rankC4 = ($minC4['C4'] / $f['C4']) * $bobotC4['bobot'];
         $rankC5 = ($f['C5'] / $maxC5['C5']) * $bobotC5['bobot'];
         $nilai = $rankC1 + $rankC2 + $rankC3 + $rankC4 + $rankC5;

         $data = [
             'npm' => $npm,
             'nilai' => $nilai
         ];
         
         $this->seleksi->inputreport($data);
            
          
        if ($i++ == $this->input->post('max')) break;
        endforeach; 
        
        $this->toastr->success('Saved!');
        redirect('admin');
        
    }

我想将数据从高到低保存$nilai(排名)。请帮帮我。使用排序方法,但它不起作用。喜欢排序($nilai);

标签: phpcodeigniter

解决方案


推荐阅读