第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如果嵌套在 PHP 中,如何使用?

如果嵌套在 PHP 中,如何使用?

PHP
至尊寶的傳說 2022-06-11 09:59:35
我有一個(gè)關(guān)于使用 if else 嵌套在 php 中的問題,這$hasilkonsentrasi是不可讀的,謝謝<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";     }    }   }   elseif ($hasil[3] > $hasil[0]) {    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>
查看完整描述

2 回答

?
BIG陽

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>


查看完整回答
反對 回復(fù) 2022-06-11
?
當(dāng)年話下

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ì)變得不可讀。


查看完整回答
反對 回復(fù) 2022-06-11
  • 2 回答
  • 0 關(guān)注
  • 128 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號