Tuesday, March 3, 2015

PHP III - Percabangan


PHP - Percabangan adalah suatu teknik coding untuk menampilkan informasi yang memiliki beberapa kemungkinan yang bisa terjadi sesuai dengan input yang diberikan.

<!DOCTYPE html>
<html>
<body>

<?php

$nilai = 55;

echo"<h1 style='color:blue;'>Percabangan & Function</h1>
<h3>Percabangan If-Else</h3>
<div>Nilai : $nilai</div>";
if ($nilai >  "0" AND $nilai <  "20") {
     echo "Predikat Nilai = E";
}elseif ($nilai >  "20" AND $nilai <  "40") {
     echo "Predikat Nilai = D";
}elseif ($nilai >  "40" AND $nilai <  "60") {
     echo "Predikat Nilai = C";
}elseif ($nilai >  "60" AND $nilai <  "80") {
     echo "Predikat Nilai = B";
}elseif ($nilai >  "80" AND $nilai <  "100") {
     echo "Predikat Nilai = A";
}

$favcolor = "red";

echo"<h3>Percabangan Switch Case</h3>
<div>Colour : $favcolor</div>";
switch ($favcolor) {
     case "red":
         echo "Your favorite color is red!";
         break;
     case "blue":
         echo "Your favorite color is blue!";
         break;
     case "green":
         echo "Your favorite color is green!";
         break;
     default:
         echo "Your favorite color is neither red, blue, or green!";
}

//Function
echo"<h3>Function</h3>";
function kelas($fname, $urutan) {
    echo "Teman Kelas $urutan : $fname.<br>";
}

kelas("Agus",1);
kelas("Joko",2);
kelas("Widodo",3);
kelas("Mawar",4);
kelas("Putri",5);
?>
  
</body>
</html>