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.

egghead
egghead
~ 10 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today