Fungsi Perulangan (While) pada PHP

Perulangan (while) adalahsebuahkondisi di manasatuataubeberapabariskode program (statement) dieksekusisecaraberulang-ulang.

Contoh 1 :


<html>
<body>

<?php
$i=1;
while($i<=5)
{
echo "nomer " . $i . "<br />";
$i++;
}
?>

</body>
</html>


Hasildari coding diatasadalah :


nomer 1
nomer 2
nomer 3
nomer 4
nomer 5

Contoh 2 :


html>
<body>

<?php
$i=1;
do
{
$i++;
echo "nomer " . $i . "<br />";
}
while ($i<=5);
?>

</body>
</html>


Hasil dari coding diatasadalah :


nomer 2

nomer 3
nomer 4
nomer 5
nomer 6

Contoh 3 :


<html>
<body>

<?php
$x=array("one","two","three");
foreach ($x as $value)
{
echo $value . "<br />";
}
?>

</body>
</html>


Hasildari coding diatasadalah :


one

two
three

1 Response to "Fungsi Perulangan (While) pada PHP"

  1. manteb min, bermanfaat sekali...
    http://cody.id/produk/lcd-separator/

Posting Komentar

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme