Topic Overview

Welcome to today's session on "Multidimensional Arrays and Their Traversal in PHP". Multidimensional arrays in PHP allow you to store arrays within each index instead of single elements. Think of it as an 'apartment building' with floors (outer array) and apartments on each floor (inner array). Our goal today is to build a solid understanding of these 'apartment buildings' and how to handle them effectively in PHP.

Creating Multidimensional Arrays

To create a multidimensional array in PHP, we use arrays of arrays. Here is an example demonstrating how to create and work with 2D arrays.

Indexing in Multidimensional Arrays

All indices in PHP arrays are 0-based. Suppose you want to visit an apartment on the second floor (index 1) and deliver a package to the first unit (index 0) in this building. Here's how you can do it:

By using the indices [1][0], you can access the value 4. The number 1 refers to the second inner array, while 0 refers to the first element in that array.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal