I
I
Ivan2015-10-08 16:09:43
PHP
Ivan, 2015-10-08 16:09:43

How to pass input field values ​​to an array?

Good afternoon.
Help adding input field values ​​to php array.
The form:

<form method="post">
   <inpute type="text" name="optio">
   <inpute type="text" name="optio">
   <inpute type="text" name="optio">
 </form>

Well, click on the button:
if (isset($_POST['save'])) {
  $MassCh[$i]=$_POST['optio'];
}
Но при таком варианте добавляется в массив все и в одну ячейку и это не странно.

Then I tried it with an array and a script when generating a new field, a number is added to name="optio" and I add it to the cells through the array like this:
for ($i=1; $i<=$valueLine; $i++) {
            $MassCh[$i]=$_POST['option'.$i];
        }

But not sure if this is the correct solution?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexey Ukolov, 2015-10-08
@Shucach

<input type="text" name="field[]">
B $_POST['field']will already have an array of filled values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question