HENDIKA

Thursday, 27 February 2014

 for
Berguna untuk pengulangan yang sudah ditentukan terlebih dahulu awalnya berapa, dijalankan sampai kondisi bagaimana.
Sintaks :
for(awal; kondisi; penambahan){
    kode untuk dijalankan
}

Contoh :
<?php
for ($i = 1; $i <= 10; $i++) {
    echo $i."<br>";
}
?>

while
Berguna untuk menjalankan suatu kode terus menerus selama kondisi bernilai TRUE
Sintaks :
while(kondisi){
    kode untuk dijalankan;
}
Contoh :
<?php
$i=1;
while($i<=5)
{
    echo "Nomor : " . $i . "<br />";
    $i++;
}
?>

foreach
Perulangan untuk array yang mempunyai nilai
Sintaks :
foreach (array as $value){
    statement
}
atau
foreach (array as $key => $value){
    statement
}
Contoh :
<?php
$arr = array("satu", "dua", "tiga");

foreach($arr as $key => $value) {
    echo "Key: $key; Value: $value<br />\n";
}
?>
27 Feb 2014

0 komentar:

Post a Comment

:) :)) ;(( :-) =)) ;( ;-( :d :-d @-) :p :o :>) (o) [-( :-? (p) :-s (m) 8-) :-t :-b b-( :-# =p~ $-) (b) (f) x-) (k) (h) (c) cheer
Click to see the code!
To insert emoticon you must added at least one space before the code.

 
Loading...