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
-
lesson
The foreach Loop in PHP