Backend and Infrastructure

PHP Arrays and Loops

Sprout Video

We've seen how we can create variables and set each to a string or a number. We've also used functions like rand and strtoupper to return numbers and strings. Let's talk about a third type of variable in PHP: an array. An array represents a group of things, like 5 random numbers or 3 strings. They're a really important type of data in PHP, and you'll be using them often. In this lesson we'll create an array, and then use foreach to loop through the array so we can complete a repetitive action for each item in the array. We'll also look at how you can access a specific item in an array, explaining keys and indexes.

Additional resources

PHP Manual: Arrays