Hello.

There is a form, the number of fields that are sent to php is always different, so everything is set through variables:

$conex=2 // номер выпадающего поля из ряда, всегда разный $colnum=4; // количество полей for ($i = 1; $i <= colnum; $i++) {if ($i==$conex)continue; echo '<input type=text name=foo'.$i. '>'; // примерно такой инпут у формы $foo1=$_post[foo1]; // // Все они таким же способом через for генерируются 

There is an array:

 $arr = array("$id;$foo1;$foo3;$foo4); // условие на формирование фу такое же, как и у полей (for), то есть всегда есть то, что игнорируется print_r($arr); // Должно быть примерно так: Array ( [0] => 88;Text 1; Текст 3; Текст 4 ) то есть текст 2 игнорируется 

Question: how here $arr = array("$id; !место! );

Paste what I have generated in a similar way, like for

Then $arr will be loaded into the csv file, so I need to have such an array at the output: Array ( [0] => 88;Text 1;Текст 3;Текст 4). Perhaps within the framework of my question there is no solution and the desired is realized in a different way, in this case, I ask you to throw in an idea for that. PS I am writing from the phone.

    1 answer 1

     $conex=2; $colnum=4; $foo=array(); for ($i = 1; $i <= colnum; $i++) { if ($i==$conex)continue; echo '<input type=text name=foo'.$i. '>'; $foo[$i] = $_post["foo".$i]; } $arr = array("$id;".implode(";", $foo)); 

    Another question is why you need to store only one line in the array.

    • Sorry, should this work if foo itself is not specified? I have a problem with this. With the separation sign. With foo [$ i] = $ _post ["foo". $ I]; I have no problems, in the example I wrote the information on the output. The same I need to organize in an array. That is to force it for example $ arr = array ("$ id;". For ($ i = 1; $ i <= colnum; $ i ++) {if ($ i == $ conex) continue; echo ';'. $ Foo [$ i];})); Work - Dvashington
    • @Dvashington if you look closely at my code, you will see that the element of the $ foo [$ conex] array is not created. Accordingly, the gluing it does not fall - rjhdby
    • I think it will work. You laid out each element of the array, and then glued it together. I did not think of it before. Although the decision was obvious. - Dvashington