SlideShare uma empresa Scribd logo
1 de 31
By I Wayan Simpen 17 September 2011 With Pemrograman Web 2
FUNGSI/FUNCTION ,[object Object],[object Object],17 September 2011 Function  nama_fungsi  ([parameter]) { blok kode }
Contoh: 17 September 2011 Function  cetak_tebal  ($teks ) { print (“<b> $teks</ b>”); } Nama Fungsi Parameter Blok Code
Contoh Lengkap 17 September 2011 <? php function  ctk_tebal( $teks ) {   print (&quot;<br><b> $teks </b>&quot;); } function  ctk_miring( $teks ) {   print (&quot;<br><i> $teks </i>&quot;); }
17 September 2011 function  judul() { print (&quot;<center>IMPLEMENTASI FUNGSI&quot;); ctk_tebal(&quot;STMIK&quot;); ctk_miring(&quot;Dipanegara Makassar&quot;); print (&quot;</center><hr>&quot;); } judul(); ctk_tebal(&quot;STMIK&quot;); ctk_miring(&quot;Dipanegara Makassar&quot;); ?>
Hasil 17 September 2011
Nilai Balik ,[object Object],[object Object],17 September 2011
Contoh 17 September 2011 <? php function  kuadrat($bilangan) { $tmp  =  $bilangan  *  $bilangan ; return   $tmp ; } print (&quot;<U>KUADRAT BILANGAN</U><BR>&quot;); printf (&quot;5<sup>2</sup> = %f&quot;,kuadrat(5)); print (&quot;<BR>&quot;); printf (&quot;5.5<sup>2</sup> = %f&quot;,kuadrat(5.5));  ?>
Hasil 17 September 2011
Melewatkan nilai dengan Referensi ,[object Object],17 September 2011
Contoh: 17 September 2011 <? php function  tukar( $x ,  $y ) { $tmp  =  $x ; $x   =  $y ; $y   =  $tmp ; }
17 September 2011 $a  = 10; $b  = 20; print (&quot;Sebelum penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;,  $a ,  $b ); tukar( $a ,  $b ); print (&quot;Sesudah penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;,  $a ,  $b ); ?>
Hasil 17 September 2011 Tidak ada   perubahan
Contoh: ( gunakan tanda   & ) 17 September 2011 <? php function  tukar( & $x ,  & $y ) { $tmp  =  $x ; $x   =  $y ; $y   =  $tmp ; }
17 September 2011 $a  = 10; $b  = 20; print (&quot;Sebelum penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;,  $a ,  $b ); tukar( $a ,  $b ); print (&quot;Sesudah penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;,  $a ,  $b ); ?>
Hasil 17 September 2011 Ada Perubahan
Lingkup Variavel ,[object Object],[object Object],[object Object],[object Object],[object Object],17 September 2011
Contoh: 17 September 2011 <? php function  ganti() { $bunga  = &quot;Mawar&quot;; } $bunga  = &quot;Melati&quot;;  Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (“Setelah Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel  berbeda
Hasil 17 September 2011
Contoh: 17 September 2011 <? php function  ganti() {  global   $bunga ; $bunga  = &quot;Mawar&quot;; } $bunga  = &quot;Melati&quot;;  Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (&quot;Sebelum Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel  Yang sama VARIABEL GLOBAL
Hasil 17 September 2011
ATAU: 17 September 2011 <? php function  ganti() {  $GLOBALS [“bunga”] = &quot;Mawar&quot;; } $bunga  = &quot;Melati&quot;;  Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (&quot;Sebelum Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel  Yang sama ARRAY GLOBAL
Hasil 17 September 2011
Variabel Statis ,[object Object],[object Object],[object Object],[object Object],17 September 2011
Contoh: 17 September 2011 <? php function  hitung() { static   $pencacah  = 0; return   ++$pencacah ; } printf (&quot;%d <BR>&quot;, hitung()); printf (&quot;%d <BR>&quot;, hitung()); printf (&quot;%d <BR>&quot;, hitung()); ?>
Hasil 17 September 2011
Fungsi Rekursive ,[object Object],[object Object],17 September 2011
Contoh: 17 September 2011 <?php function  faktorial( $m ) { if ( $m  == 0) return  1; else return   $m  * faktorial( $m  - 1); } printf (&quot;1! = %d <BR>&quot;, faktorial(1)); printf (&quot;4! = %d <BR>&quot;, faktorial(4)); ?>
Hasil 17 September 2011
[object Object],17 September 2011 Catatan:   Gunakan fungsi  rekursi
[object Object],17 September 2011

Mais conteúdo relacionado

Destaque

110127 Papier Industrie
110127 Papier Industrie110127 Papier Industrie
110127 Papier IndustrieRobBrager
 
Ance_Torretta_24052011
Ance_Torretta_24052011Ance_Torretta_24052011
Ance_Torretta_24052011Rèdais
 
Digital Groep Congres 2011 Presentatie Hans v.d. Ven
Digital Groep Congres 2011 Presentatie Hans v.d. VenDigital Groep Congres 2011 Presentatie Hans v.d. Ven
Digital Groep Congres 2011 Presentatie Hans v.d. VenDigital groep
 
Ance_Gallano_24052011
Ance_Gallano_24052011Ance_Gallano_24052011
Ance_Gallano_24052011Rèdais
 
Brincos Lissy Joias
Brincos Lissy JoiasBrincos Lissy Joias
Brincos Lissy Joiaslissyjoias
 
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...juliarosich
 
SignDirect - ofta eller sällan?
SignDirect - ofta eller sällan?SignDirect - ofta eller sällan?
SignDirect - ofta eller sällan?SignDirect
 
Milliora Assicura - Polizza Infortuni
Milliora Assicura -  Polizza InfortuniMilliora Assicura -  Polizza Infortuni
Milliora Assicura - Polizza InfortuniMilliora Assicura
 
Pensamiento positivo y la plenitud de la vida
Pensamiento positivo y la plenitud de la vidaPensamiento positivo y la plenitud de la vida
Pensamiento positivo y la plenitud de la vidaEuler Ruiz
 
รายชื่อสอบสอน...วันที่
รายชื่อสอบสอน...วันที่รายชื่อสอบสอน...วันที่
รายชื่อสอบสอน...วันที่Valentine Iiw
 
Conflitos amb.trab
Conflitos amb.trabConflitos amb.trab
Conflitos amb.trabPedro Eliel
 

Destaque (20)

110127 Papier Industrie
110127 Papier Industrie110127 Papier Industrie
110127 Papier Industrie
 
Ance_Torretta_24052011
Ance_Torretta_24052011Ance_Torretta_24052011
Ance_Torretta_24052011
 
Digital Groep Congres 2011 Presentatie Hans v.d. Ven
Digital Groep Congres 2011 Presentatie Hans v.d. VenDigital Groep Congres 2011 Presentatie Hans v.d. Ven
Digital Groep Congres 2011 Presentatie Hans v.d. Ven
 
Asam,basa dan garam
Asam,basa dan garamAsam,basa dan garam
Asam,basa dan garam
 
บทที่ 7
บทที่ 7บทที่ 7
บทที่ 7
 
Ance_Gallano_24052011
Ance_Gallano_24052011Ance_Gallano_24052011
Ance_Gallano_24052011
 
Brincos Lissy Joias
Brincos Lissy JoiasBrincos Lissy Joias
Brincos Lissy Joias
 
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...
Malalties del Son. De la mitologia classica a l'actualitat, passant per Matri...
 
SignDirect - ofta eller sällan?
SignDirect - ofta eller sällan?SignDirect - ofta eller sällan?
SignDirect - ofta eller sällan?
 
Sala de belleza
Sala de bellezaSala de belleza
Sala de belleza
 
Presentac..[1]
Presentac..[1]Presentac..[1]
Presentac..[1]
 
Milliora Assicura - Polizza Infortuni
Milliora Assicura -  Polizza InfortuniMilliora Assicura -  Polizza Infortuni
Milliora Assicura - Polizza Infortuni
 
Pensamiento positivo y la plenitud de la vida
Pensamiento positivo y la plenitud de la vidaPensamiento positivo y la plenitud de la vida
Pensamiento positivo y la plenitud de la vida
 
รายชื่อสอบสอน...วันที่
รายชื่อสอบสอน...วันที่รายชื่อสอบสอน...วันที่
รายชื่อสอบสอน...วันที่
 
Topoguía Galego
Topoguía GalegoTopoguía Galego
Topoguía Galego
 
Video boccelli
Video boccelliVideo boccelli
Video boccelli
 
A cigarra-e-a-formiga
A cigarra-e-a-formigaA cigarra-e-a-formiga
A cigarra-e-a-formiga
 
Metamorfosis 1
Metamorfosis 1Metamorfosis 1
Metamorfosis 1
 
บทที่1
บทที่1บทที่1
บทที่1
 
Conflitos amb.trab
Conflitos amb.trabConflitos amb.trab
Conflitos amb.trab
 

Mais de Rani Sarungallo Rombe (11)

WEB II PHP 11 odbc 2
WEB II PHP 11 odbc 2WEB II PHP 11 odbc 2
WEB II PHP 11 odbc 2
 
WEB II PHP 10 odbc 1
WEB II PHP 10 odbc 1WEB II PHP 10 odbc 1
WEB II PHP 10 odbc 1
 
WEB II PHP 09 text
WEB II PHP 09 textWEB II PHP 09 text
WEB II PHP 09 text
 
WEB II PHP 07
WEB II PHP 07WEB II PHP 07
WEB II PHP 07
 
WEB II PHP 06
WEB II PHP 06WEB II PHP 06
WEB II PHP 06
 
WEB II PHP 05
WEB II PHP 05WEB II PHP 05
WEB II PHP 05
 
WEB II PHP 04
WEB II PHP 04WEB II PHP 04
WEB II PHP 04
 
WEB II PHP 03
WEB II PHP 03WEB II PHP 03
WEB II PHP 03
 
WEB II PHP 02
WEB II PHP 02WEB II PHP 02
WEB II PHP 02
 
WEB II PHP 01
WEB II PHP 01WEB II PHP 01
WEB II PHP 01
 
Wek14 mysql 2
Wek14 mysql 2Wek14 mysql 2
Wek14 mysql 2
 

WEB II PHP 06.ppt

  • 1. By I Wayan Simpen 17 September 2011 With Pemrograman Web 2
  • 2.
  • 3. Contoh: 17 September 2011 Function cetak_tebal ($teks ) { print (“<b> $teks</ b>”); } Nama Fungsi Parameter Blok Code
  • 4. Contoh Lengkap 17 September 2011 <? php function ctk_tebal( $teks ) { print (&quot;<br><b> $teks </b>&quot;); } function ctk_miring( $teks ) { print (&quot;<br><i> $teks </i>&quot;); }
  • 5. 17 September 2011 function judul() { print (&quot;<center>IMPLEMENTASI FUNGSI&quot;); ctk_tebal(&quot;STMIK&quot;); ctk_miring(&quot;Dipanegara Makassar&quot;); print (&quot;</center><hr>&quot;); } judul(); ctk_tebal(&quot;STMIK&quot;); ctk_miring(&quot;Dipanegara Makassar&quot;); ?>
  • 7.
  • 8. Contoh 17 September 2011 <? php function kuadrat($bilangan) { $tmp = $bilangan * $bilangan ; return $tmp ; } print (&quot;<U>KUADRAT BILANGAN</U><BR>&quot;); printf (&quot;5<sup>2</sup> = %f&quot;,kuadrat(5)); print (&quot;<BR>&quot;); printf (&quot;5.5<sup>2</sup> = %f&quot;,kuadrat(5.5)); ?>
  • 10.
  • 11. Contoh: 17 September 2011 <? php function tukar( $x , $y ) { $tmp = $x ; $x = $y ; $y = $tmp ; }
  • 12. 17 September 2011 $a = 10; $b = 20; print (&quot;Sebelum penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;, $a , $b ); tukar( $a , $b ); print (&quot;Sesudah penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;, $a , $b ); ?>
  • 13. Hasil 17 September 2011 Tidak ada perubahan
  • 14. Contoh: ( gunakan tanda & ) 17 September 2011 <? php function tukar( & $x , & $y ) { $tmp = $x ; $x = $y ; $y = $tmp ; }
  • 15. 17 September 2011 $a = 10; $b = 20; print (&quot;Sebelum penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;, $a , $b ); tukar( $a , $b ); print (&quot;Sesudah penukaran : &quot;); printf (&quot;a = %d b = %d <BR>&quot;, $a , $b ); ?>
  • 16. Hasil 17 September 2011 Ada Perubahan
  • 17.
  • 18. Contoh: 17 September 2011 <? php function ganti() { $bunga = &quot;Mawar&quot;; } $bunga = &quot;Melati&quot;; Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (“Setelah Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel berbeda
  • 20. Contoh: 17 September 2011 <? php function ganti() { global $bunga ; $bunga = &quot;Mawar&quot;; } $bunga = &quot;Melati&quot;; Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (&quot;Sebelum Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel Yang sama VARIABEL GLOBAL
  • 22. ATAU: 17 September 2011 <? php function ganti() { $GLOBALS [“bunga”] = &quot;Mawar&quot;; } $bunga = &quot;Melati&quot;; Print (&quot;Sebelum Penggantian = &quot;); print (&quot; $bunga &quot;); print (&quot;<br>&quot;); ganti(); Print (&quot;Sebelum Penggantian = &quot;); Print (&quot; $bunga &quot;); ?> Dua variabel Yang sama ARRAY GLOBAL
  • 24.
  • 25. Contoh: 17 September 2011 <? php function hitung() { static $pencacah = 0; return ++$pencacah ; } printf (&quot;%d <BR>&quot;, hitung()); printf (&quot;%d <BR>&quot;, hitung()); printf (&quot;%d <BR>&quot;, hitung()); ?>
  • 27.
  • 28. Contoh: 17 September 2011 <?php function faktorial( $m ) { if ( $m == 0) return 1; else return $m * faktorial( $m - 1); } printf (&quot;1! = %d <BR>&quot;, faktorial(1)); printf (&quot;4! = %d <BR>&quot;, faktorial(4)); ?>
  • 30.
  • 31.