PHP 8 Beginner Basics · 1 min read

foreach over arrays

Start the PHP 8 learning path »

❮ PHP 8 Home All Tutorials ❯

How do I loop an array in PHP?

foreach value / key=>value.

Example

PHP 8 Example
<?php
$skills = ['HTML', 'CSS', 'PHP'];
foreach ($skills as $skill) {
  echo $skill;
}
$student = ['name' => 'Ada', 'year' => 1];
foreach ($student as $key => $value) {
  echo $key . '=' . $value;
}

Line-by-Line Walkthrough

Best loop for arrays and collections.

Need more coins?

You do not have enough coins for this action.

Your balance: 0 coins

Share

Reactions

Loading reactions…