3

I am working on an application which, in the end, will produce a .CSV file. I have already found how to turn an array or arrays into a .CSV file, but I am having trouble figuring out the preceding step.

I have a bunch of html inputs in a form that will be sent to PHP, I am hoping to have one array consisting of all the input names (input name="example") and another array that consists of the values put into those fields by the end user.

In the end I was the CSV to be a product of both arrays. The first row being things like Height, Width, Depth, and the second row being 10 mm,20 mm,9 mm, etc etc.

I am wondering if a mixture of html classes and a foreach could be used, but I'm really not sure. Any help would be great! Thanks!!

1 Answer 1

10

using the square bracket notation will convert these named fields into arrays, here are a few examples

<input name="array[]">
<input name="array[]">
<input name="array[]">

<input name="array[foo]">
<input name="array[bar]">

<input name="array[0][foo]">
<input name="array[0][bar]">
<input name="array[1][foo]">
<input name="array[1][bar]">

Then to get a quick preview of your data use var_dump() or print_r()

var_dump($_REQUEST['array']);
Sign up to request clarification or add additional context in comments.

2 Comments

Oh great! Thank you so much. I'm a little new with arrays though (im sorry!). I just want to make sure I understand, am I able to name more than one array with my inputs? Like input 1-5 go to an array named "Awesome" and 5-10 go to "Donuts" or something.
Sure, the word "array" here can be replaced with your own name. Also if you're happy with this answer, please click the tick icon under the number next to this answer!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.