From the course: Learning PHP
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Defining arrays
- [Instructor] Now that you know what arrays are, let's look at how to use them in PHP, starting with indexable arrays. I'll write my opening php tags. I'll add a comment here, Indexable Array. And let's create that colors array. So the array is going to have a name, just like any other variable with a dollar sign first. So I'll say colors get and then we're going to use the keyword array. And inside of the parentheses for the array function or keyword, we're going to have a comma-separated list of items. So we'll say red, blue, and green. So if we want to see what this array looks like, we can use a special function called print_r that will print the array nicely for us. So we'll say print_r colors. I'll save this and then I'll go to the browser. And you could see that the array is a simple array with our indexes as numbers, starting at zero. That means that if we want to reference a specific color, we would do so…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.