1. 22
    Create a list using a PHP array
    1m 11s

Create a list using a PHP array

Mark Shust
InstructorMark Shust
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Lists are found in every programming language, and PHP is no exception. Let's learn how to create a list using an array.

Instructor: [0:00] Sometimes, you need to store a list of data. In this example of a blog, this may be a collection of tags to categorize the content of our posts. First, let's remove this match statement, since we will no longer be using this logic.

[0:16] Next, let's create a new variable named tags. This tags variable will be equal to a left and right bracket. Within this bracket, we can define any number of items separated with commas.

[0:32] We can store a list of years, for example, 1999, 2000, 2001, or we can store a list of strings. This is what we will do for our tags. If we are creating a blog about programming, this may be something like PHP, Docker, MySQL.

[0:53] We can store any number of tags in this array, and it can be as long as we wish. This is similar to creating three separate variables, but instead of doing that, this is a lot more concise and allows us to store multiple units of data within a single variable.