STRUCTURAL CONTROL STATEMENT If If…..else…. If ….elseif…else
A PHP script is a set of statements Statements can be assignments / assignment, function calls, loops, conditions even an empty statement. In general, statements end with a semicolon (;)
Used to execute a block of statements if it meets certain conditions The syntax is: If the condition is true (true), the statement block will be done. if (condition) statement block
statement if <?php $Nilai = 95; $Keterangan = "Tidak Lulus"; if ($Nilai >=60) { $Keterangan = "Lulus";} printf("Nilai = %d ", $Nilai); printf("Keterangan = %s ",$Keterangan); ?>
Statement if <?php $Tabungan = ""; $Sukubunga = 0; $Tipe=1; if($Tipe=1){ $Tabungan = "Pribadi"; $Sukubunga=2.6; } if($Tipe=2){ $Tabungan = "Perusahaan Kecil"; $Sukubunga=3.3; } if($Tipe=3){ $Tabungan = "Perusahaan Besar"; $Sukubunga=3.6; } print ("Tipe Tabungan = $Tipe "); print ("Jenis Tabungan= $Tabungan "); print ("Suku Bunga = $Sukubunga "); ?>
statement IF Nilai Siswa : <?php if (isset ($Nilai)) { //Mengambil nilai integer $Nilai = intval ($Nilai); if ($Nilai >= 60) { $Keterangan = "Lulus"; } else { $Keterangan = "Tidak Lulus"; } print ("Nilai Ujian = $Nilai "); print ("Keterangan = $Keterangan"); } ?>
Principally similar to the statement of if If... else... used for two branching. If a condition is met, then do a block of statement 1, if not met, do block of statements 2. syntax if (kondisi) { blok pernyataan 1; } Else { blok pernyataan 2; } if (kondisi): blok pernyataan1; Else: blok pernyataan2; Endif; atau
Statement IF Nilai Siswa: <?php if (isset($Nilai)) { if ($Nilai >=90) $Indeks = "A"; elseif ($Nilai >=80) $Indeks = "B"; elseif ($Nilai >=70) $Indeks = "C"; elseif ($Nilai >=60) $Indeks = "D"; else $Indeks = "E"; if ($Nilai >=60) $Keterangan = "Lulus"; else $Keterangan = "Tidak Lulus"; print ("Nilai Ujian = $Nilai "); print ("Keterangan = $Keterangan "); print ("Indeks =$Indeks"); } ?>
The first meeting is finished, you can download these materials at download the menu, the course material ( filename = PHPMySQL3,Kamboja.) thank you see you at the next meeting