Programming language designed for building dynamic web applications Server-side Scripting Internet Web Browser Apache PHP MySQL Disk Drive
PHP code begins with the tag " “ Or with the simple form like “ ” Every command or statement in PHP code must end with a semicolon ";" <?php echo “Hello World”; ?> <? echo “Hello World”; ?>
PHP inner HTML PHP dalam HTML <?php echo “ Paragraf 2 : Teks dari kode PHP ”; ?> <?php PHP dalam HTML <?php echo “ Paragraf 2 : Teks dari kode PHP ”; ?> <?php
HTML inner PHP <?php echo “ ”; echo “ HTML dalam PHP ”; echo “ ”; echo “ Paragraf 2 : Teks dari kode PHP ”; echo “ ”; ?> <?php echo “ ”; echo “ HTML dalam PHP ”; echo “ ”; echo “ Paragraf 2 : Teks dari kode PHP ”; echo “ ”; ?>
Integer Float String Boolean Array
assignment operator › = aritmatic operator › +, -, *, /, %, ++, -- relasional operator › ==, !=, >, >=, <, <= logic operator › &&, ||, !
‘If’ Conditional If (condition) { Statemen; } else { Other Statemen; } If (condition) { Statemen; } else { Other Statemen; }
‘Switch’ Conditional <?php Switch ($month) { case 1 : case 2 : case 3 : case 4 : case 5 : echo “Mei”; case 6 : case 7 : case 8 : echo “August”; case 9 : echo “September”; case 10 : case 11 : case 12 : default : echo “This is default statement.”; exit(); } ?> <?php Switch ($month) { case 1 : case 2 : case 3 : case 4 : case 5 : echo “Mei”; case 6 : case 7 : case 8 : echo “August”; case 9 : echo “September”; case 10 : case 11 : case 12 : default : echo “This is default statement.”; exit(); } ?>
‘While’ Loop <?php while(expression) { Statement; } ?> <?php while(expression) { Statement; } ?>
‘do-while’ Loop <?php do { Statement; } while (expression); ?> <?php do { Statement; } while (expression); ?>
‘For’ Loop <?php for(inisialisation; expression; increment/decrement) { Statement; } ?> <?php for(inisialisation; expression; increment/decrement) { Statement; } ?>
‘Foreach’ Loop <?php foreach($array as $current) { Statement; } ?> <?php foreach($array as $current) { Statement; } ?>
Pemula PHP <?php echo " Awal Mula "; echo "Hello World "; print "Hello World "; echo " "; echo " Variable "; $angka = 99; echo "Ini adalah angka = $angka "; $angka_2 = $angka + 1; echo "Ini hasilnya = $angka_2 "; echo " "; echo " Looping "; for ($i=0; $i<=$angka_2; $i++) { echo "Urutan ke $i. "; } ?> Pemula PHP <?php echo " Awal Mula "; echo "Hello World "; print "Hello World "; echo " "; echo " Variable "; $angka = 99; echo "Ini adalah angka = $angka "; $angka_2 = $angka + 1; echo "Ini hasilnya = $angka_2 "; echo " "; echo " Looping "; for ($i=0; $i<=$angka_2; $i++) { echo "Urutan ke $i. "; } ?>