<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test5</title>
</head>
<body>
<?php
// if else
function check($your_number){
if ($your_number < 50){
return "too small";
} else if ( $your_number <100) {
return "medium";
} else{
return "too much babes";
}
}
echo check(20); echo "<br>"; //too small
echo check(60); echo "<br>"; //medium
echo check(120); //too much babes
// switch, break
$grade = 'D';
switch ($grade){
case "A":
echo " you got A grade";
break;
case "B":
echo " not bad";
break;
case "C":
echo "hmm not good";
break;
case "D":
echo " holy sheet what a noob";
break;
} // holy sheet what a noob
//while
$i=1;
while ($i<=100){
echo $i;
echo "<br>";
$i++;
} // 1 - 100
//do while
$iteration=101;
do {echo $iteration;
$iteration++;
// kode bakal dieksekusi minimal sekali walaupun salah
}
while ($iteration <100); // 101
//for
for ($jumlah=1;$jumlah<=5;$jumlah++){
echo $jumlah;
echo "<br>";
} // 1 - 5
//foreach
$array1 = array("satu","dua","tiga","empat");
foreach ($array1 as $variabel){
echo "$variabel <br>";
} // satu dua tiga empat
?>
</body>
</html>
No comments:
Post a Comment