How foreach actually works in PHP

Asked

Viewed 57 times

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?

  • How the foreach works, I can’t understand this function, what it does.

  • 2

    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 of for on it you do not need to control the indexer, increment or decrease and the stop condition.

  • the "as" means what?

  • 1

    @Lucascarvalho as separates the key from the value: forearch( $colecao as $chave => $valor ) { ...

  • 1

    What comes after the as vc can interpret as the iterated element (current)

  • 1
  • This article should help you @Lucascarvalho: https://medium.com/weyes/usando-structures-repeating-no-php-7b51cf34247a

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.