🌐
W3Schools
w3schools.com › php › php_looping_for.asp
PHP for loop
The PHP for loop - Loops through a block of code a specified number of times.
🌐
PHP
php.net › manual › en › control-structures.for.php
PHP: for - Manual
Looping through letters is possible. I'm amazed at how few people know that. for($col = 'R'; $col != 'AD'; $col++) { echo $col.' '; } returns: R S T U V W X Y Z AA AB AC Take note that you can't use $col < 'AD'. It only works with != Very convenient when working with excel columns.
Discussions

What is the best event loop extension for PHP 7.0 and greater?
I think there's not that much difference performance wise. stream_select is usually limited to 1024 FDs via FD_SETSIZE, but other than that, I'm not aware of important differences to choose one over the other. uv has the benefit of coming with filesystem support directly without the need for eio or multiple parallel PHP processes for async filesystem access. More on reddit.com
🌐 r/PHP
12
21
July 2, 2017
I wrote a little function for Rate Limiting in PHP. Does the logic look sound? Comments welcome.

I tried using the Leaky Bucket and Token Bucket implementations but they space out the requests evenly

As author of bandwidth-throttle/token-bucket I'm very interested why token bucket did not work out for you. Could you please elaborate what you mean by "they space out the requests evenly"?

Still I would recommend using a token bucket (with a capacity of 30) for your API. Here's a short example with my library:

$storage  = new SingleProcessStorage();
$rate     = new Rate(30, Rate::SECOND);
$bucket   = new TokenBucket(30, $rate, $storage);
$consumer = new BlockingConsumer(bucket);
$bucket->bootstrap(30);

while(true) {
    $consumer->consume(1);
    // Send SMS.
}
More on reddit.com
🌐 r/PHP
12
18
July 26, 2015
For $mysqli->query("SELECT * FROM table"); Why does PHP make you loop through results and call a "fetch" function on each one rather than just return an array with all of the results?

You can also use fetch_all.

As for why - what if your table had millions of records? Or each row had a 16 MB blob. Most database engines in any language will return a cursor which you must iterate to yield results.

More on reddit.com
🌐 r/webdev
24
5
September 13, 2015
PHP Fibers: The Event Loop
I would encourage you to add such a link; Revolt is really the only game in town for Fiber-based event loops, and it's best for the ecosystem to keep it that way. ... This is a follow up to my prior post, PHP Fibers: A Practical Example. More on reddit.com
🌐 r/PHP
6
19
September 4, 2023
🌐
W3Schools
w3schools.com › php › php_looping_foreach.asp
PHP foreach loop
The PHP foreach loop - Loops through a block of code for each element in an array or each property in an object.
🌐
C.S. Rhymes
csrhymes.com › 2021 › 09 › 13 › the-php-for-loop.html
The PHP for loop | C.S. Rhymes
September 13, 2021 - Adding the code into a loop means you only have to write it once, and you also only have to maintain the code in one place in future. The PHP for loop allows you to loop a defined number of times, until a defined condition is no longer true.
🌐
W3Schools
w3schools.com › php › php_looping.asp
PHP Loops
... do...while - loops through a block of code once, and then repeats the loop as long as the specified condition is true · for - loops through a block of code a specified number of times
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-loops
PHP Loops - GeeksforGeeks
April 10, 2025 - In this article, we will discuss the different types of loops in PHP, their syntax, and examples. ... PHP for loop is used when you know exactly how many times you want to iterate through a block of code.
🌐
W3Resource
w3resource.com › php-exercises › php-for-loop-exercises.php
PHP for loop - Exercises, Practice, Solution - w3resource
March 31, 2026 - Practice with solution of exercises on PHP for Loop, examples on various mathematical series, display various string pattern and more from w3resource.
🌐
Codecademy
codecademy.com › learn › learn-php › modules › php-loops › cheatsheet
Learn PHP: Loops in PHP Cheatsheet | Codecademy
In PHP, while loops repeat execution of their code block as long as their conditional statement is true. ... In PHP, the foreach loop is used for iterating over an array.
Find elsewhere
🌐
PHPpot
phppot.com › php › loop-control-structure
PHP Loops: while, do while, for, foreach, break and continue - PHPpot
May 27, 2026 - Nested loops are commonly used for tables, grids, and matrix-style data. <?php for ($row = 1; $row <= 3; $row++) { for ($col = 1; $col <= 2; $col++) { echo "Row " . $row . " Col " .
🌐
Codecademy
codecademy.com › learn › php-arrays-and-loops › modules › learn-php-loops-sp › cheatsheet
PHP Arrays and Loops: PHP Loops Cheatsheet | Codecademy
In PHP, while loops repeat execution of their code block as long as their conditional statement is true. ... In PHP, the foreach loop is used for iterating over an array.
🌐
w3resource
w3resource.com › php › statement › for.php
PHP for loop - w3resource
<?php $text="The quick brown Fox jumps over the lazy Dog"; $words = explode(" ", $text); // explode function looks for " " and creates an array, where each word is an element of the array $now = count($words); $j = 0; for($i=0; $i<$now; $i++) { if ($words[$i] == "the" or $words[$i] == "The") { $j = $j+1; } } echo $j; ?>
🌐
Udemy
blog.udemy.com › home › it & development › web development › php for loops: how to use the for loop in php
PHP FOR Loops: How to Use the FOR Loop in PHP - Udemy Blog
April 14, 2026 - A PHP for loop is a control structure that repeats a code block a set number of times using three parameters: a starting condition, a continue condition, and an ending condition. This article covers syntax, practical examples, the BREAK statement, ...
🌐
FlatCoding
flatcoding.com › home › php for loop: run code using a counter with examples
PHP For Loop: Run Code Using a Counter with Examples - FlatCoding
July 1, 2025 - PHP for loop repeats code a set number of times using a counter. It defines start, stop, and increment to control the code. Click here ...
🌐
GeeksforGeeks
geeksforgeeks.org › php › php-for-loop
PHP for Loop - GeeksforGeeks
August 25, 2022 - The for loop is the most complex loop in PHP that is used when the user knows how many times the block needs to be executed.
🌐
freeCodeCamp
freecodecamp.org › news › how-loops-work-in-php-beginners-guide
How Loops Work in PHP: A Complete Guide for Beginners
June 18, 2025 - In the following section, you will learn about another loop called foreach. Let’s move on. PHP’s foreach loop is built to work with arrays. It lets you move through each item in the array, one at a time.
🌐
The Knowledge Academy
theknowledgeacademy.com › blog › php-for-loop
PHP For Loop: Introduction, Syntax, and Examples
March 5, 2026 - PHP For Loop follows a step-by-step execution process. First, the initialisation step is executed, followed by the evaluation of the condition. If the condition is found to be true, the code block is executed.
🌐
8gWiFi
8gwifi.org › tutorials › php › loops-for.jsp
PHP For Loops - PHP Tutorial | 8gwifi.org
The for loop is perfect when you know exactly how many times you need to iterate. With initialization, condition, and increment all in one place, it's the cleanest way to write counted loops. ... <?php // for ($i = 1; $i <= 3; $i++) // Step 1: $i = 1 (initialization - runs once) // Step 2: Is $i <= 3?
🌐
Tutorialspoint
tutorialspoint.com › php › php_loop_types.htm
PHP - Loop Types
PHP supports following four loop types. For Loop: Loops through a block of code a specified number of times.
🌐
Medium
medium.com › @TechnologyDiaries › php-loops-the-complete-developers-guide-c3731b05009a
PHP Loops: The Complete Developer’s Guide | by Technology Diaries | Medium
August 9, 2025 - The for loop is perfect when you know exactly how many times you want to repeat something. for (initialization; condition; increment) { // Code to execute } <?php // Print numbers 1 to 5 for ($i = 1; $i <= 5; $i++) { echo "Number: " .