Selemat datang di Blog Teknologi Informasi . Semoga Bermanfaat :D . Butuh Jasa pembuatan aplikasi Sistem Berbasis web Hubungi Saya Nursidik HP : 085311047193;

Search This Blog

Wednesday, 6 July 2016

Script Perulangan di PHP

Script Perulangan sangat menjadi kebutuhan di pemrograman dan kali ini saya akan berbagi perulangan di PHP

For

<?php/* example 1 */for ($i 1$i <= 10$i++) {
    echo 
$i;
}
/* example 2 */for ($i 1; ; $i++) {
    if (
$i 10) {
        break;
    }
    echo 
$i;
}
/* example 3 */$i 1;
for (; ; ) {
    if (
$i 10) {
        break;
    }
    echo 
$i;
    
$i++;
}
/* example 4 */for ($i 1$j 0$i <= 10$j += $i, print $i$i++);?>

For Each

<?php
$arr 
= array(1234);
foreach (
$arr as &$value) {
    
$value $value 2;
}
// $arr is now array(2, 4, 6, 8)unset($value); // break the reference with the last element?>

While

<?php/* example 1 */$i 1;
while (
$i <= 10) {
    echo 
$i++;  /* the printed value would be
                   $i before the increment
                   (post-increment) */
}/* example 2 */$i 1;
while (
$i <= 10):
    echo 
$i;
    
$i++;
endwhile;
?>


Semoga bermanfaat :D

0 comments:

Post a Comment