Lists are found in every programming language, and PHP is no exception. Let's learn how to create a list using an array.
Duration
1 min
Access
Pro
Transcript
Available
Lists are found in every programming language, and PHP is no exception. Let's learn how to create a list using an array.
Video Transcript
Instructor: 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.
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.
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.
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.
Duration
1 min
Access
Pro
Transcript
Available
Course lesson
Create a list using a PHP array
Lists are found in every programming language, and PHP is no exception. Let's learn how to create a list using an array.
Access required
This lesson is available with an active egghead membership.