0
Could someone explain how really works the foreach and how to use? I’ve researched and can not understand, I’ve seen it right here in stackoveflow, has THAT ONE topic, but it is not explained, I would just like to understand, because I am studying, and I am in the part of vectors and matrices and began to appear the foreach, and I’m not understanding.
What is the doubt?
– rray
How the foreach works, I can’t understand this function, what it does.
– Lucas de Carvalho
It goes through the elements of an array basically. Is there any example of code that shows something you don’t understand? for/foreach are not functions are repetition structure. The
foreach
is a straight-up version offor
on it you do not need to control the indexer, increment or decrease and the stop condition.– rray
the "as" means what?
– Lucas de Carvalho
@Lucascarvalho
as
separates the key from the value:forearch( $colecao as $chave => $valor ) { ...
– bfavaretto
What comes after the
as
vc can interpret as the iterated element (current)– rray
I think that’s a better answer: What’s the difference between while, for, while and foreach?
– rray
This article should help you @Lucascarvalho: https://medium.com/weyes/usando-structures-repeating-no-php-7b51cf34247a
– Yure Pereira