Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created August 3, 2018 23:10
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save IhwanID/ad81a875a703a9048fc880fb100c7ff5 to your computer and use it in GitHub Desktop.
sample code of function in php
<?php
function ucapSalam() {
echo "Assalamualaikum";
}
//cara panggil function
ucapSalam();
function namaKeluarga($namaAwal) {
echo "$namaAwal Udin.<br>";
}
namaKeluarga("Jamal");
namaKeluarga("Sarif");
namaKeluarga("Nur");
namaKeluarga("Arief");
namaKeluarga("Rohman");
function biodata($nama, $tahun) {
echo "Si $nama . Lahir pada tahun $tahun <br>";
}
biodata("Andi", "1997");
biodata("Kusuma", "2008");
biodata("Novanto", "1887");
function setTinggi($minTinggi = 150) {
echo "Tinggi nya Dia adalah : $minTinggi <br>";
}
setTinggi(350);
setTinggi(); // Akan menggunakan nilah default
setTinggi(135);
setTinggi(80);
function tambah($x, $y) {
$z = $x + $y;
return $z;
}
echo "6 + 12 = " . tambah(6, 12) . "<br>";
echo "9 + 13 = " . tambah(9, 13) . "<br>";
echo "2 + 44 = " . tambah(2, 44);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment