35 of 110 menu

PHP Array Iteration

To iterate over an array in PHP, the foreach loop is used.

Let's say we have an array:

<?php $arr = [1, 2, 3, 4, 5]; ?>

Let's use the foreach loop to display all its elements on the screen:

<?php $arr = [1, 2, 3, 4, 5]; foreach ($arr as $elem) { echo $elem; } ?>

Code execution result:

12345

See Also

English
БеларускаяEspañolРусский
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline