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.

Organizing the form data into arrays

Organizing the form data into arrays - PHP Tutorial

From the course: PHP for Web Designers

Start my 1-month free trial

Organizing the form data into arrays

Now that we've seen how to find and extract a substring from a longer string, we can return to order.php in the Hansel and Petal site, and organize the form data into new arrays. First we need to create three empty arrays for color, quantity, and image. We only want those arrays if the form has been submitted, so we'll put them inside this if block here. I'm not going to delete this code here on lines three, four, and five, because we'll use that later for some testing. So our new arrays, first one will be color, and I'm going to use the array keyword to create the empty array. This will work on all servers, of course if you are using PHP 5.4 or later on your server you can use the shorthand version, this will work everywhere. So, that's why I'm using the keyword, and then the last one wil be image. Next we need to go through the post array and we'll use a foreach loop to handle it looking at each key and each value so foreach all one word. And the array is $_POST, all in caps. And…

Contents