PHP - While Loop

PHP While loop do over and over tasks as long as the specified condition is true.

Syntax:
while (condition){
    // to do
}



Ex:
<?php
    $counter = 1;

    while($counter <= 10){
        echo "This is : " . $counter . "<br />";
        $counter++;
    }
?>

Output:
 

Another Example:
<table border="1">
    <tr>  
        <td>No</td>
        <td>Design</td>
    </tr>
    <tr>
<?php
    $counter = 1;  
    while($counter <= 10){
        $subCount = 1;
        echo "<td>" . $counter . "</td><td>";
        while ($subCount <= $counter){
            echo "* ";
            $subCount++;
        }
        echo "</td></tr>";
        $counter++;
    }
?>

</table>

Output

No comments:

Post a Comment