The information presented in arrays can vary in value type and size, and the number of elements cannot always be determined in advance. Modern programming, especially in the distributed version, allows you to create complex data structures, the content and properties of which can be determined dynamically at an indefinite moment in time as a result of various actions or events, in various sequences.

It is not always possible to predict the operation process at the development stage, to provide for all possible options for the presentation and use of information, the dynamics of their appearance and use.
Syntax for loop by content
In formulating the foreach syntax, PHP offered two options for accessing elements. Both do not depend on the type of the key or the type of the value and can be emulated with a regular loop. It is proposed to consider an array as a collection of elements, the number of which is not initially determined. An array can be formed on the fly, with or without keys. An element can be removed from an array, keys can beassociative and formed by default.
foreach ($aArrayName as $xValue) { loop body }
This construct forces the PHP foreach loop to go through all the elements in a row. In the body of the loop, the $xValue variable will sequentially receive all the values of the $aArrayName array in the order in which they were added. Item key values will not be available.
foreach ($aArrayName as $xKey=> $xValue) { loop body }
Here, too, executing the foreach construct, PHP will look at the entire contents of the array, but in the loop body, both the $xValue variable and the $xKey variable, the element key, will take the corresponding values in pairs.

Sequence of elements
Inside foreach PHP will offer the content in the order in which the elements were added, but if there were repeated additions/deletions during the formation of the array, and something was added with keys, and something without, then it is best to do working with an array not from the positions of the sequence of elements, but based on their content or on the keys.

Due to various objective reasons, the sequence within the array may not be observed and/or may not be of particular importance, but it should not be relied upon in any case. In simple tasks, on trivial data sets, there are no problems, and the algorithm can be configured for sequential processing, but when many factors affect the process of creating / editing an array, one should focus oncontent.
Modern "correct" elements
From the standpoint of the existing own concept, without even taking into account even unconditionally similar languages, the PHP foreach array must be designed independently, taking into account the real specific task.
The practice when there is a given, and the given has an index in the general collection of similar ones according to a certain criterion - that was yesterday.
The index has become the key, and the array has become an associative array. That is, the key lost its sequential uniqueness (usually it was sequential: 0, 1, 2, … n) and became also a value, but a simple value (i.e. key) associated with a real value (i.e. the content of the element). It's today, it's right, but not perfect.
This is why PHP sees the foreach loop as an alternative to the regular array oriented loop. This is first of all, and this is what is very important, because the real correctness of the elements of the array follows from this, as well as their keys!
Correct arrays of correct elements
First there was an element, then two elements… so an array of elements appeared and a loop through the array of them:
for ($i=0; $i<count($aArrayName); $i++) {
processing body of each $aArrayName[$i]
}
Then, instead of the faceless 0, 1, 2, … n, the element got its own name - the key, and then the arrays became associative and then the foreach loop was needed - "loop for each":
foreach ($aArrayName as $xKey=> $xValue) {
processing body of each $aArrayName[$xKey] or $xValue which is the same
}
Now the time has come when the correct elements should come to the array, that is, those that are themselves. They themselves know their index, their content, their place in the sequence, they tend to show their own choice of sequence and delegate all these capabilities to the actual array that contains them.
Such regular arrays will be processed by themselves. There will simply not be a special need to use ordinary cycles and cycles for each. Formally, the syntax and semantics already allow this, the only question is the inertia of the developer's consciousness.