Summary: in this tutorial, you will learn how to use PHP foreach statement to loop over elements of an array.
Introduction to the PHP foreach statement #
PHP provides you with the foreach statement that allows you to iterate over elements of an array, either an indexed array or an associative array.
The foreach statement iterates over all elements in an array, one at a time. It starts with the first element and ends with the last one. Therefore, you don’t need to know the number of elements in an array upfront.
The following flowchart illustrates how the foreach statement works: