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

Storing multiple values in a variable as an array - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

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…

Contents