With a question about foreach and incrementing another helper to perform an insert in the database, see:
When I send a form via post I get the following array as a result:
array (size=2)
'quantidade' =>
array (size=8)
0 => string '10' (length=2)
1 => string '11' (length=2)
2 => string '15' (length=0)
3 => string '22' (length=0)
4 => string '10' (length=0)
5 => string '9' (length=0)
6 => string '0' (length=0)
7 => string '35' (length=0)
'produto' =>
array (size=8)
0 => string '11' (length=1)
1 => string '18' (length=1)
2 => string '19' (length=1)
3 => string '21' (length=1)
4 => string '22' (length=2)
5 => string '25' (length=2)
6 => string '29' (length=2)
7 => string '22' (length=2)
As I'm using CodeIgniter to get the data from the Form, I'm using the following structure:
foreach ($this->input->post() as $chave => $valor) {
//o array aux aqui
}
Some idea how to generate this result, taking the first value of each element and inserting it in an auxiliary array:
Type like this:
$array_aux[0] = array('quantidade' => 10, 'produto' => 11)
...
$array_aux[7] = array('quantidade' => 35, 'produto' => 22)