From the course: PHP for Web Designers
Unlock the full course today
Join today to access over 22,500 courses taught by industry experts or purchase this course individually.
Looping through an array's values - PHP Tutorial
From the course: PHP for Web Designers
Looping through an array's values
Whenever you encounter an array more often then not you want to do something with each array element. That's what loops are for. They access each element in turn so you can decide what to do with it. So let's use a loop to turn the flowers array on lines two and three above the dock type into an unordered list inside the body of the page. By the way, although we're working with an array that's been hard coded above the doc type, many arrays are created automatically. For example, as you'll see in the next chapter, data submitted from an online form, is structured as an array. So working with arrays and loops is a very important part, of learning how to use php. So let's get to work. To create an unordered list underneath the h1 heading we need to put some HTML tags, UL, and then a closing UL tag. Now, between those two tags we'll create a php block and this is where the loop will go. There are many different types of loop in php. The one we're going to use is dedicated specifically…
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)
-
-
-
-