Foreach Loop

This lesson discusses the foreach loop and its implementation in PHP.

Introduction

The foreach statement is similar to the for statement in that both allow code to iterate over the items of collections, but the foreach statement lacks an iteration index, so it works even with collections that lack indices altogether.

Syntax

It is written in the following form:

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy