From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Storing multiple values in a variable as an array - PHP Tutorial
From the course: PHP for Web Designers
Storing multiple values in a variable as an array
In this chapter, we'll explore arrays and loops. An array is simply a way of storing multiple values in a single variable and a loop allows you to get to each individual value in turn. This chapter lays the foundation for working with online forms and displaying database results later in the course. So, how do you create an array? Well, let's begin by creating a PHP block above the doctype. You store an array in an ordinary variable. So in keeping with the floral theme of the Hansel and Petal website that we've been using in the course, let's create an array called flowers, then the equal sign. And there are two ways to create an array. The original way is to use the array keyword and then a pair of parentheses after that. And between the parentheses, you create a comma separated list of all the items that you want in the array. You can put anything in an array. You can put numbers, you can put strings, you can put other things. You can even put other arrays inside an array. I'm going…
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.
Contents
-
-
-
-
-
-
(Locked)
Storing multiple values in a variable as an array4m 28s
-
(Locked)
Inspecting an array's elements4m 13s
-
(Locked)
Challenge: Inserting the appropriate alt text1m 27s
-
(Locked)
Solution: Inserting the appropriate alt text5m 26s
-
(Locked)
Displaying an array as a comma-separated list3m 13s
-
(Locked)
Looping through an array's values7m 17s
-
(Locked)
Labeling array elements7m 21s
-
(Locked)
Looping through an array's labels and values5m 29s
-
Finding if a value exists in an array3m 51s
-
(Locked)
Challenge: Displaying a seasonal feature3m 6s
-
(Locked)
Solution: Displaying a seasonal feature8m 30s
-
(Locked)
-
-
-
-