10
PHP Lanjutan Euis Marlina, S.Kom Email : [email protected] http://euismarlina.edublogs.org HP : 08179424319

Materi 6 - PHP Lanjutan

Embed Size (px)

Citation preview

Page 1: Materi 6 - PHP Lanjutan

PHP Lanjutan

Euis Marlina, S.Kom

Email : [email protected]://euismarlina.edublogs.orgHP : 08179424319

Page 2: Materi 6 - PHP Lanjutan

Kondisi

If

syntax :

if (expr)

statement;

<?phpif ($a > $b)    echo "a is bigger than b";?>

Page 3: Materi 6 - PHP Lanjutan

Else

contoh :

<?phpif ($a > $b) {    echo "a is bigger than b";} 

else 

{    echo "a is NOT bigger than b";}?>

Page 4: Materi 6 - PHP Lanjutan

Else if

Contoh :<?phpif ($a > $b) {    echo "a is bigger than b";} else if ($a == $b) {    echo "a is equal to b";} else {    echo "a is smaller than b";}?>

Page 5: Materi 6 - PHP Lanjutan

Switch

contoh :<?php

switch ($i) {case 0:    echo "i equals 0";    break;case 1:    echo "i equals 1";    break;case 2:    echo "i equals 2";    break;}?>

Page 6: Materi 6 - PHP Lanjutan

Switch untuk string

<?phpswitch ($i) {case "apple":    echo "i is apple";    break;case "bar":    echo "i is bar";    break;case "cake":    echo "i is cake";    break;}?>

Page 7: Materi 6 - PHP Lanjutan

Perulangan

Whilesyntax :while (expr)

statement;

Contoh:<?$i = 1;while ($i <= 10) { echo $i++; echo "<br />"; }?>

Page 8: Materi 6 - PHP Lanjutan

do-while

syntax :

<?php$i = 0;do {    echo $i;} while ($i > 0);?>

Page 9: Materi 6 - PHP Lanjutan

Forsyntax :for (expr1; expr2; expr3)

statement;

contoh:<?php/* example 1 */

for ($i = 1; $i <= 10; $i++) {    echo $i;}

Page 10: Materi 6 - PHP Lanjutan

/* example 2 */

for ($i = 1; ; $i++) {    if ($i > 10) {        break;    }    echo $i;}

/* example 3 */

$i = 1;for (; ; ) {    if ($i > 10) {        break;    }    echo $i;    $i++;}