我有一组数据$all_scholar_grade
,其中包含成绩值。第二个系列中的这些等级不是从
最高阶。这不能按升序进行,因为它不是查询。我如何安排或排名从最高到最低
使用循环还是foreach?我试着搞清楚,但我无法理解。
$all_scholar_id = array();
$all_scholar_grade = array();
$count = 0;
foreach ($card_id as $id) {
$card = ScholarCard::find($id);
if ($card->scholar_grade_level == 12) {
if ($card->scholar_GPA == 100 || $card->scholar_GPA == 99 || $card->scholar_GPA == 98 || $card->scholar_GPA == 97 || $card->scholar_GPA == 96 || $card->scholar_GPA == 95 ) {
$card_gpa = 1.0;
}elseif ($card->scholar_GPA == 94) {
$card_gpa = 1.1;
}elseif ($card->scholar_GPA == 93) {
$card_gpa = 1.2;
}elseif ($card->scholar_GPA == 92) {
$card_gpa = 1.3;
}elseif ($card->scholar_GPA == 91) {
$card_gpa = 1.4;
}elseif ($card->scholar_GPA == 90) {
$card_gpa = 1.5;
}elseif ($card->scholar_GPA == 89) {
$card_gpa = 1.6;
}elseif ($card->scholar_GPA == 88) {
$card_gpa = 1.7;
}elseif ($card->scholar_GPA == 87) {
$card_gpa = 1.8;
}elseif ($card->scholar_GPA == 86) {
$card_gpa = 1.9;
}elseif ($card->scholar_GPA == 85) {
$card_gpa = 2.0;
}elseif ($card->scholar_GPA == 84) {
$card_gpa = 2.1;
}elseif ($card->scholar_GPA == 83) {
$card_gpa = 2.2;
}elseif ($card->scholar_GPA == 82) {
$card_gpa = 2.3;
}elseif ($card->scholar_GPA == 81) {
$card_gpa = 2.4;
}elseif ($card->scholar_GPA == 80) {
$card_gpa = 2.5;
}elseif ($card->scholar_GPA == 79) {
$card_gpa = 2.6;
}elseif ($card->scholar_GPA == 78) {
$card_gpa = 2.7;
}elseif ($card->scholar_GPA == 77) {
$card_gpa = 2.8;
}elseif ($card->scholar_GPA == 76) {
$card_gpa = 2.9;
}elseif ($card->scholar_GPA == 75) {
$card_gpa = 3.0;
}elseif ($card->scholar_GPA <= 74) {
$card_gpa = 5.0;
}
}else{
$card_gpa = $card->scholar_GPA;
}
if ($card_gpa >= $scholarship->scholarship_gpa_to || $card_gpa <= $scholarship->scholarship_gpa_from) {
$all_scholar_grade[] = $card_gpa;
$all_scholar_id[] = $card->scholar_id;
}
$count++;
}
我的dd的输出($ all_scholar_id,$ all_scholar_grade)
array:4 [▼
0 => 29
1 => 34
2 => 35
3 => 36
]
array:4 [▼
0 => 1.5
1 => 2.1
2 => 1.3
3 => 1.5
]
这是所需的输出:
array:4 [▼
1.3 => 35
1.5 => 36
1.5 => 29
2.1 => 34
]