Iterating with foreach

foreach iterates over an array element by element. With $cle => $valeur, it also provides the key. By default the value is a copy; use & to modify it in place, with caution because the reference stays active after the loop.

Example

foreach ($user as $cle => $valeur) {
  echo "$cle : $valeur\n";
}

Related concepts

The whole glossary