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

Looping through an array's values - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

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…

Contents