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.
Labeling array elements - PHP Tutorial
From the course: PHP for Web Designers
Labeling array elements
Using numbers to identify array elements is fine in many situations, particularly if the array is a simple collection of related values, like this array of flowers here. But it does have its limitations. Incidentally, this type of array is often called an indexed array. The number acting as a sort of index for each element. But PHP also lets you use text instead of automatically assigned numbers as the key for each array element. In effect, the key acts as a label. So let's go to our editing program and create such an array. The way that you create an array like this is very similar. Let's begin by using a variable. The variable I'm going to use is features, and equals, and then array. The array keyword, are a comma separated list. Inside a pair of parentheses. With this type of array I like to put everything on a separate line. It makes it a lot easier to read. An that makes maintenance a lot easier. So let's indent a little bit. And, we begin, with the array key, which is a string…
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)
-
-
-
-