The PHP-while Loop is one of several loops in PHP that uses the while loop statement when we iterate through the data: Oh, well, let me take a look at it.
Repetitive tasks are always a burden to us. Delete spam, 50 envelopes sealed, and go to work are examples of tasks that repeat. The benefit of this approach is on the program, and you can avoid this repetitive task with a little extra thought. Usually these repetitive tasks are the conquest of the cycle.
Advertising tizag.com
The idea of one ring is to do something over and over again until the task has been completed. Before we show you a real example, when you might need a, let's go to the structure of the PHP while loop.
Simple example, while the loop
The function of the loop is to do a good job, much as long as the specified conditional statement is true. This is the logical check, as one appears in a PHP if statement to determine whether it is true or false. This is the basic structure of the PHP while loop:
while (conditional statement is true) {
do this code;
}
This is not an invalid PHP code, but it shows how the while loop is structured. This is breaking how the loop functions while your script executes:
In the conditional statement is the check. If this is true, then (2) occurs. If it is false, then (4) occurs.
The while loop within the code is executed.
The process starts again (1). Effectively "loop" back.
If a conditional declaration is false, then the code is not executed and no more loops. The following code is followed by a while loop, and then like normal execution.
An example of a true while loop
Imagine that you are running an art-supply store. You want to print out the quantity of the price list brushes and the total cost. You sell brushes at a flat rate, but to show how many different amounts of fees. This will save your client from having to do psychological math itself.
You know, a while loop will be this perfect repetition and tedious task. Here's how to do it.
$brush _price = 5;
$counter = 10;
Echo "<table border=" 1 "align=" center ">";
echo "<tr><th>Quantity</th>";
Echo "<th>Price</th></tr>";
while ($counter <=) {
echo "<tr><td>";
Echo $counter;
echo "</td><td>"; br> echo $brush _price * $counter;
echo "</td></tr>";
$counter = $counter + 10;
}
Echo "</table>";
Quantity |
| Price
10 |
50 |
20 |
100 |
30 |
150 |
40 |
200 |
50 |
250 |
60 |
300 |
70 |
350 |
80 |
400 |
90 |
450 |
100 |
500 |