Last active
December 15, 2015 23:22
-
-
Save indrakaw/4707439942fa7af97a2a to your computer and use it in GitHub Desktop.
Self-explanation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# Dibuat pada 15 November 2015. | |
# Untuk pempelajaran WebProgramming IKSR 2015-2016. | |
# Coded by @IndraKaw. | |
// Fungsi pangkat x^n | |
function pangkat($nilai, $pangkat) { | |
$hasil = 1; | |
for ($i=1; $i <= $pangkat; $i++) { | |
$hasil=$hasil*$nilai; | |
} | |
return $hasil; | |
} | |
// Fungsi faktorial n! | |
function faktorial($nilai) { | |
if ($nilai < 2) { | |
return 1; | |
} else { | |
// difungsikan nilai sendiri. | |
return ($nilai * faktorial($nilai-1)); | |
} | |
} | |
// Fungsi leadingzero 00123 | |
function leadingzero($nilai, $size) { | |
return sprintf("%0".$size."d",$nilai); | |
} | |
// Cetak deret hari dalam Bahasa Indonesia | |
function namahari() { | |
$namahari = array( | |
"", // biarkan kosong untuk nilai 0 | |
"Senin", | |
"Selasa", | |
"Rabu", | |
"Kamis", | |
"Jum'at", | |
"Sabtu", | |
"Mingu", | |
); | |
return $namahari; | |
} | |
// Cetak deret bulan dalam Bahasa Indonesia | |
function namabulan() { | |
$namabulan = array( | |
"", // biarkan kosong untuk nilai 0 | |
"Januari", | |
"Februari", | |
"Maret", | |
"April", | |
"Mei", | |
"Juni", | |
"Juli", | |
"Agustus", | |
"September", | |
"Oktober", | |
"November", | |
"Desember", | |
); | |
return $namabulan; | |
} | |
// Fungsi mengambil tanggal sekarang | |
function tanggalSekarang() { | |
$namahari = namahari(); // Cetak array nama hari | |
$namabulan = namabulan(); // Cetakarray nama bulan | |
$today = getdate(); // Dapatkan deret array waktu sekarang ini. | |
$hari = $namahari[$today['wday']]; // Loopup namahari | |
$bulan = $namabulan[$today['mon']]; // Lookup namabulan | |
// Cetak string tanggal sekarang | |
$tanggalSekarang = $hari .", ". $today['mday'] ." ". $bulan ." ". $today['year']; | |
return $tanggalSekarang; | |
} | |
// Output | |
echo "2^4 = "; | |
echo pangkat(2, 4); | |
echo "</br>"; | |
echo "5! = "; | |
echo faktorial(5); | |
echo "</br>"; | |
echo "LeadngZero(21, 4): "; | |
echo leadingzero(21, 4); | |
echo "</br>"; | |
echo "Tanggak Sejarang: "; | |
echo tanggalSekarang(); | |
echo "</br>"; | |
// Print array date, untuk eksperimental. | |
// echo "<hr>"; | |
// print_r(getdate()); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment