Chapter 27 Nested Loop Control Structures

27.1 What is a Nested Loop?

A nested loop is a loop within another loop or, in other words, an inner loop within an outer one.

The outer loop controls the number of complete iterations of the inner loop. This means that the first iteration of the outer loop triggers the inner loop to start iterating until completion. Then, the second iteration of the outer loop triggers the inner loop to start iterating until completion again. This process repeats until the outer loop has performed all of its iterations.

Take the following PHP script, for example.

 file_27.1
<?php
for ($i = 1; $i <= 2; $i++) {
for ($j ...

Get PHP and Algorithmic Thinking for the Complete Beginner now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.