foreach($sorted AS $rows) {
  foreach($rows AS $row) {
  ...
  }
}

or with keys/indices

foreach($sorted AS rows) {
  foreach($rows AS $index => $row) {
Answer from djot on Stack Overflow
🌐
PHP
php.net › manual › en › control-structures.while.php
PHP: while - Manual
It tells PHP to execute the nested statement(s) repeatedly, as long as the while expression evaluates to true. The value of the expression is checked each time at the beginning of the loop, so even if this value changes during the execution ...
Discussions

How do you look through a 2D array in PHP using a while loop
Edit; missed the "using a while loop", so updating my answer to reflect the actual requirement. Alright, so - there are a couple of options, but the basic principle could look something like this: Name Amount Price More on reddit.com
🌐 r/PHPhelp
8
1
April 5, 2022
PHP Arrays and While Loops - PHP - SitePoint Forums | Web Development & Design Community
Hi The code I have written pulls in 3 rows from the database and at present puts the values into 1 array. Each row contains 12 values. Is there any way to place them into individual arrays each time it goes through the loop, creating 3 different arrays in total? More on sitepoint.com
🌐 sitepoint.com
0
August 15, 2011
How to loop this JSON object from php?
First of all, you have an error in your JSON data. Here is the fixed one: { "data": [ { "section": "Technology", "weighting": "0.15", "questions": [ { "id": "1", "weighting": "0.25", "score": "5" }, { "id": "2", "weighting": "0.25", "score": "5" } ] }, { "section": "Data", "weighting": "0.15", "questions": [ { "id": "1", "weighting": "0.25", "score": "5" }, { "id": "2", "weighting": "0.25", "score": "5" } ] } ] } I, then, created a file 'data.json' and 'test.php'. Here is 'test.php': '; } } It prints: 0.25 0.25 0.25 0.25 As you see, you made two mistakes: Your JSON data was corrupted and you were looping the whole array, but you have to loop array['data']. Hope it helps. P.S.: Get better in debugging PHP with print_r and echoes. Really helps. More on reddit.com
🌐 r/PHPhelp
11
7
August 23, 2020
re: array_map vs foreach
array_map has the overhead of a function call for each element in the array, so yes it will be slower. In my personal benchmarks in a more production-like environment, it was never that big of a difference. More on reddit.com
🌐 r/PHP
61
37
April 15, 2017
🌐
W3Schools
w3schools.com › php › php_looping_while.asp
PHP while Loop
The PHP while loop - Loops through a block of code as long as the specified condition is true.
🌐
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.
🌐
GeeksforGeeks
geeksforgeeks.org › php › how-to-iterating-through-an-array-in-php
How to Iterate Over an Array in PHP? - GeeksforGeeks
July 23, 2025 - The PHP foreach loop is an method to iterate through an array. There is no need of index number in foreach loop. ... The PHP each() function can be used in combination with a while loop to iterate through an array while maintaining the internal ...
Find elsewhere
🌐
Dinocajic
dinocajic.com › home › programming › php — p29: while loops
PHP While Loop - PHP Loops Made Easy
June 19, 2023 - We know that we have 11 elements so our condition can be either while($i < 11) or while($i ≤ 10). If we start at 0, we’re going to end at 10 either way. Inside of the loop body, we pass the value of $i to the $best_cars_ever_made array and echo out the element that’s returned. Right after that, the variable $i is incremented and the processes is repeated. ... PHP sets $i = 0.
🌐
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.
🌐
SitePoint
sitepoint.com › php
PHP Arrays and While Loops - PHP - SitePoint Forums | Web Development & Design Community
August 15, 2011 - <?php $res = mysql_query(/**/); $rows = array(); while($row = mysql_fetch_assoc($res)){ array_push($rows, $row); } foreach($rows as $row){ echo $row['id']; }
🌐
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 .
🌐
Jobtensor
jobtensor.com › Tutorial › PHP › en › While-Loop
PHP while Loop - Syntax, Examples | jobtensor
Using the while loop print the numbers from 5 to 1 (decreasing order). <?php $var = 123; <?php $i = 5; while($i >= 1) { echo " $i <br>"; $i--; } { "test_output_contains": [ { "expected":"5", "error_message":"Sorry. Please try again." }, { "expected":"4", "error_message":"Sorry.
🌐
Tutorialspoint
tutorialspoint.com › php › php_while_loop.htm
PHP - While Loop
You can traverse an array by constituting a while loop by repeatedly accessing the element at the xth index till "x" reaches the length of the array. Here, "x" is a counter variable, incremented with each iteration.
🌐
Laravel
laravel.com › docs › 12.x › blade
Blade Templates | Laravel 12.x - The clean stack for Artisans and agents
The $loop variable also contains a variety of other useful properties: The @class directive conditionally compiles a CSS class string. The directive accepts an array of classes where the array key contains the class or classes you wish to add, while the value is a boolean expression. If the array element has a numeric key, it will always be included in the rendered class list: ... @php $isActive = false; $hasError = true; @endphp <span @class([ 'p-4', 'font-bold' => $isActive, 'text-gray-500' => !
🌐
Phpprogram
phpprogram.net › php-tutorials › while-loops-in-php-with-example
While Loops in PHP with example – PHP Developers
In PHP, the function of a while loop is to do a task, over and over as long as the specified conditional statement is true.
🌐
Sko
sko.dev › referensi › php › while-loop-php
While loop - Referensi PHP
February 3, 2023 - Dalam contoh di atas, while loop digunakan untuk menampilkan tiap elemen dalam array $fruits. Loop akan berjalan selama nilai $i lebih kecil dari jumlah elemen dalam array. While loop merupakan alat yang penting dan sering digunakan dalam PHP.
🌐
Codecademy
codecademy.com › learn › learn-php-arrays-and-loops › modules › learn-php-arrays › cheatsheet
Learn PHP: Arrays and Loops: Learn PHP Arrays Cheatsheet | Codecademy
Learn how to use for-loops and while-loops to execute the same code multiple times. ... In PHP, we can access the value that a given key points to using square brackets ([]) and the key. To add new elements to an associative array, we can use the assignment operator (=).