Backend and Infrastructure

Multi-dimensional Arrays

Sprout Video

Every key in an array is either a string or a whole number, which we programmers and mathematicians call an integer. And that's the end of the story: array keys are only ever strings or integers in all of PHP. But each value in an array can be any type of PHP value. So far we know three data types in PHP: a string, a number and an array. This means that we can have multi-dimensional arrays: an array with another one inside of it. Multi-dimensional arrays are actually pretty common and easy to use. In this lesson we're going to expand our existing array by putting the pet details inside the array. Once we have the new data in the array we'll look at how we access this nested information, and how we can count what we have in there.

PHP Manual: Arrays