2 回答
TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
句法
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
code to be executed if first condition is false and this condition is true;
} else {
code to be executed if all conditions are false;
}
最后試試這個(gè),否則不需要添加條件
<div class="alert alert-info">
<?php
if ($hasil[0] > $hasil[1]) {
if ($hasil[0] > $hasil[2]) {
if ($hasil[0] > $hasil[3]) {
$hasilkonsentrasi = "Manajemen Keamanan Jaringan";
}
}
}
elseif ($hasil[1] > $hasil[0]) {
if ($hasil[1] > $hasil[2]) {
if ($hasil[1] > $hasil[3]) {
$hasilkonsentrasi = "Teknologi Cerdas";
}
}
}
elseif ($hasil[2] > $hasil[0]) {
if ($hasil[2] > $hasil[1]) {
if ($hasil[2] > $hasil [3]) {
$hasilkonsentrasi = "Manajemen Bisnis";
}
}
}
else {
if ($hasil[3] > $hasil[1]) {
if ($hasil[3] > $hasil[2]) {
$hasilkonsentrasi = "Manajemen Data dan Informasi";
}
}
}
echo "Anda cocok mengambil konsentrasi <strong>$hasilkonsentrasi</strong>";
$mkj= number_format($hasil[0], 2, '.', '');
$tc=$hasil[1];
$mb=$hasil[2];
$mdi=$hasil[3];
$jurusan=$hasilkonsentrasi;
$user->SimpanHasilJurusan($mkj,$tc,$mb,$mdi,$jurusan);
?>
</div>
</div>
TA貢獻(xiàn)1890條經(jīng)驗(yàn) 獲得超9個(gè)贊
您似乎正在尋找的是$hasil具有最大值的條目的鍵。有很多方法可以做到這一點(diǎn),但我建議對數(shù)組進(jìn)行排序,同時(shí)保留鍵,然后在鍵值上使用開關(guān)。像這樣:
<div class="alert alert-info">
<?php
arsort($hasil);
switch(array_key_first($hasil)) {
case 0 : $hasilkonsentrasi = "Manajemen Keamanan Jaringan";
break;
case 1 : $hasilkonsentrasi = "Teknologi Cerdas";
break;
case 2 : $hasilkonsentrasi = "Manajemen Bisnis";
break;
case 3 : $hasilkonsentrasi = "Manajemen Data dan Informasi";
break;
default : $hasilkonsentrasi = "Not found";
break;
}
echo "Anda cocok mengambil konsentrasi <strong>$hasilkonsentrasi</strong>";
?>
</div>
當(dāng)數(shù)組中有 6 個(gè)條目時(shí),這仍然是可行的,而如果你想用if () else代碼來做這件事,真的會(huì)變得不可讀。
- 2 回答
- 0 關(guān)注
- 128 瀏覽
添加回答
舉報(bào)
