php - 为每个 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);
解决方案
推荐阅读
- machine-learning - 编码或映射
- javascript - Promise.all 不适用于异步函数数组
- javascript - 为什么我的下一个和上一个按钮在 IOS 上看起来很奇怪?
- cookies - XSRF 和 SOP,具有明显相似请求的不同结果
- php - 计算数组结果差异
- python - Django 规则重用谓词
- java - Selenium 卡在 WebDriver 对象上
- android - Android ProGuard: Getting an error of 'Use of generics not allowed for java type at '<1>_<2>_<3>JsonAdapter' in line 43 of file ...'
- postgresql - 迁移后错误,我有两列,为什么?
- python - Python,代码做第一件事然后循环到最后