Edward Posted September 24, 2012 Share Posted September 24, 2012 This is something that stumped me right now and i found this webpage with a useful solution. I have an inventory page in which i can select check boxes next to the product listing to end as many products as i like, there could be 10 or 20 products, depending how many the user has added. We can add our checkbox values into an array. http://www.kavoir.com/2009/01/php-checkbox-array-in-form-handling-multiple-checkbox-values-in-an-array.html Link to comment Share on other sites More sharing options...
Edward Posted September 25, 2012 Author Share Posted September 25, 2012 Just want extend on this topic, we can tidy up our registration form for example by using an array like this user[first_name]; user[last_name]; user[address]; user[age]; now if we do this we don't have to over populate our global $_POST array, with all this garbage for example $_POST['first_name'] $_POST['last_name']; $_POST['address']; $_POST['age']; We would only need instead to use $_POST['user']; This could then be banged into an array as $user = $_POST['user']; Then user can be referenced as $first_name = $user['first_name'] $last_name = $user['last_name']; $address = $user['address']; $age = $user['age']; You don't need to assign array values to separate variables its just to break it up a bit and explain. Well the reason i wanted to add this is because if you have a larger website, you need to really organize exactly what will be saved in your $_POST array so by doing this your code will be more modular. Link to comment Share on other sites More sharing options...
Larry Posted September 25, 2012 Share Posted September 25, 2012 Thanks for sharing what you've learned! Link to comment Share on other sites More sharing options...
Edward Posted September 26, 2012 Author Share Posted September 26, 2012 Yeah i was unaware of that, i have seen some sites adding that in there code, i wasn't aware that PHP would interpret that as an array, even though it was originally declared in php but in the HTML source. Link to comment Share on other sites More sharing options...
Recommended Posts