🌐
Scaler
scaler.com › topics › php-tutorial › while-loop-in-php
While Loop in PHP
April 24, 2023 - A while loop in PHP is a control structure that allows a program to execute a block of code repeatedly as long as a certain condition remains true. The condition is evaluated before each iteration of the loop, and if it's true, the loop body is executed. The loop continues until the condition ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › php tutorial › while loop in php
While Loop in PHP | How While Loop works in PHP with examples & code?
March 17, 2023 - Execution of statements inside the while loop continues until the value of the variable becomes 6. Once the value becomes 5 and the condition evaluates to be false (5 > 5), the while loop terminates, and the echo statement inside the while loop will not execute. Printing the sum of digits of a given number. ... <!DOCTYPE html> <html> <head> <title>PHP while Loop Example 2</title> </head> <body> <?PHP $number = 107; $sum=0; $rem=0; while((int)$number != 0) { $rem=$number; $sum = $sum + $rem; $number=$number/10; } echo "The Sum of digits of number given 107 is $sum"; ?> </body> </html>
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
Discussions

While Loop using PHP with a MySQL server - Stack Overflow
I have a database (SQL) with the table "Staff" with two records in it. I am required to display the contents of these records on a web page using PHP. CES St... More on stackoverflow.com
🌐 stackoverflow.com
PHP While Loop - How to update webpage / browser every irritation
You're probably running into an issue where the browser isn't outputting anything until a certain amount of data has been downloaded. The threshold in Chrome is 1KB (I think). So an example that could work in your case, could look like this: "; // Added buffer sleep(1); // visual aid ob_flush(); flush(); $counter++; } echo $buffer."All done!"; // more buffer ob_end_flush(); You're code isn't really doing anything wrong, it's just your client that impacts your results. More on reddit.com
🌐 r/PHPhelp
8
1
November 12, 2021
Is it bad practice to use foreach instead of while?
Always use FOREACH when iterating over a whole array, or at least from the top of an array to a BREAK condition. This way you will never be bitten by an "off by one" error. Always use FOR when you know (or can easily determine) exactly how many times you need to execute the code in the loop. This is also useful for iterating parts of an array where you aren't always going to be starting from the head. Use a DO-WHILE when the number of times to have to execute the loop is indeterminate, but you know the code must execute at least once. Use a WHILE loop when the looping condition could be false as you enter the loop. In other words, there could be conditions where you never execute the loop. More on reddit.com
🌐 r/PHP
37
9
June 17, 2014
Using variable inside WHILE looop
As long as $row is not falsey it will loop. Each loop iteration it checks what $row is and stops if there are no additional rows. There are some standards that avoid this syntax (declaring a variable in an if or loop) but it works. It is often a mistake or seen as a mistake as you usually use == in the same context, but the alternative to this would uses more lines of code. It's the same as: while ( true ) { $row = ...; if ( ! $row ) { break; } } More on reddit.com
🌐 r/PHPhelp
11
1
December 12, 2021
🌐
Pi My Life Up
pimylifeup.com › home › how to use the php while loop
How to Use the PHP while Loop - Pi My Life Up
March 1, 2022 - Inside the while loop, we echo a string that includes the value of x. Afterward, we increment the value of x by 1. <?php $x=1; while ($x <= 5) { echo "The value of x is " .
🌐
Tizag
tizag.com › phpT › whileloop.php
PHP Tutorial - While Loop
Learn how to use a while loop in PHP in Tizag.com's PHP While Loops lesson.
🌐
FlatCoding
flatcoding.com › home › php while loop: iterating through code blocks
PHP While Loop: Iterating Through Code Blocks - FlatCoding
April 15, 2025 - The while loop in PHP is a type of loop that can be used to repeat a block of PHP code until the loop exits the execution when it returns false by the condition.
🌐
HTML Academy
htmlacademy.org › courses › php-basics › php-arrays-loops › php-while-loop
The while loop in PHP — Arrays and loops in PHP — HTML Academy
In the product.php file on line 16 create a counter variable $index with the value 0. On line 19 write an empty while () {} loop.
🌐
W3Schools
w3schools.com › php › php_looping_while.asp
PHP while Loop
json_decode() json_encode() json_last_error() PHP Keywords · abstract and as break callable case catch class clone const continue declare default do echo else elseif empty enddeclare endfor endforeach endif endswitch endwhile extends final finally fn for foreach function global if implements include include_once instanceof insteadof interface isset list namespace new or print private protected public require require_once return static switch throw trait try use var while xor yield yield from PHP Libxml
🌐
PHP
php.net › manual › en › control-structures.while.php
PHP: while - Manual
Like with the if statement, you can group multiple statements within the same while loop by surrounding a group of statements with curly braces, or by using the alternate syntax: ... <?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; ?>
Find elsewhere
🌐
Tutorialspoint
tutorialspoint.com › home › php › php while loop
PHP While Loop
May 26, 2007 - The echo statement in the loop body prints the current iteration number, and increments the value of x, so that the condition will turn false eventually. <?php $x = 1; while ($x<=10) { echo "Iteration No.
🌐
Codecademy
codecademy.com › learn › learn-php › modules › php-loops › cheatsheet
Learn PHP: Loops in PHP Cheatsheet | Codecademy
Otherwise, the loop terminates. The third is evaluated after each iteration. ... In PHP, while loops repeat execution of their code block as long as their conditional statement is true.
🌐
Simplilearn
simplilearn.com › home › resources › software development › guide to understand loop in php
PHP Loop: For, ForEach, While, Do While [With Example] | Simplilearn
September 9, 2025 - Loop in PHP is an Iterative Control Structure to be executed until a certain condition is met. Learn more about PHP For, ForEach, While, Do While loop Now!
Address   5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Jobtensor
jobtensor.com › Tutorial › PHP › en › While-Loop
PHP while Loop - Syntax, Examples | jobtensor
Below is an example of the while loop. The code outputs the numbers from 1 to 10. <?php $i = 1; while($i <= 10) { echo " $i <br>"; $i++; }
🌐
KoderHQ
koderhq.com › tutorial › php › iteration-control-do-while-foreach-for
PHP Loops (while, do-while, foreach & for) Tutorial | KoderHQ
We can think of a for loop as a condensed version of the while loop. A for loop has the counter and increment/decrement built-in as expressions. ... This may seem somewhat confusing at first, let’s consider an example and then do a break down of what happens. ... <?php // counter condition counter increment/decrement for ($i = 1; $i <= 10; $i++) { echo $i .
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-do-while-loop
PHP do-while Loop - GeeksforGeeks
August 25, 2022 - <?php // Declare a number $num = 0; // do-while Loop do { $num += 5; echo $num .
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-while-loop
PHP while Loop - GeeksforGeeks
August 22, 2022 - <?php // Declare a number $num = 10; // While Loop while ($num < 20): echo $num .
🌐
Home and Learn
homeandlearn.co.uk › php › php5p4.html
php tutorials: while loops
Instead of using a for loop, you have the option to use a while loop. The structure of a while loop is more simple than a for loop, because you’re only evaluating the one condition. The loop goes round and round while the condition is true. When the condition is false, the programme breaks ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-loops
PHP Loops - GeeksforGeeks
April 10, 2025 - PHP for loop is used when you know exactly how many times you want to iterate through a block of code. It consists of three expressions: Initialization: Sets the initial value of the loop variable. Condition: Checks if the loop should continue. Increment/Decrement: Changes the loop variable after each iteration. ... Example: Printing numbers from 1 to 5 using a for loop. ... The while loop is also an entry control loop like for loops.
🌐
Studytonight
studytonight.com › php › php-while-and-dowhile-loop
PHP While Loop and Do While Loop | Studytonight
Let's take another example where even if the condition is false, still the loop will be executed once. <?php $a = 11; do { echo $a; $a++; // incrementing value of a by 1 } while($a <= 10) ?>