How to create nested array from information received via POST

Asked

Viewed 374 times

1

Given the array below:

$aDup = array(
    array('35342-1','2016-06-20','300.00'),
    array('35342-2','2016-07-20','300.00'),
    array('35342-3','2016-08-20','300.00'),
    array('35342-4','2016-09-20','300.00')
);

I created something like:

for($i=0; $i<$dados['dados']['n-parcelas']; $i++){
    $val .= "array('".$id."-".($i+1)."','".$dados['dados']['vencimento-parcela'][$i]."','".$dados['dados']['parcela'][$i]."'),";
}
$val = substr($val, 0, -1);
$aDup = array($val);

But to no avail.

The information shall feed the following variables::

foreach ($aDup as $dup) {
        $nDup = $dup[0]; // Código da Duplicata
        $dVenc = $dup[1]; // Vencimento
        $vDup = $dup[2]; // Valor
        $resp = $nfe->tagdup($nDup, $dVenc, $vDup);
}
  • The first code does not result in the third? I did not understand the object nor how this 'conversion' should be done, could give more details;?

  • I want to take the first code and "create it" using information received via $_POST. @rray

  • Puts a print_r() of $_POST in the question.

1 answer

2


If it is array don’t need to make a string, does everything in array even:

$arraySaida = array();

for ($i = 0; $i < $dados['dados']['n-parcelas']; $i++) {
    $arraySaida[] = array(
                       $id.'-'. ($i+1),
                       $dados['dados']['vencimento-parcela'][$i],
                       $dados['dados']['parcela'][$i]
                    );
}

print_r($arraySaida);

Note that the $arraySaida[] works similar to the array_push(), is added a array within the array of the variable $arraySaida

Browser other questions tagged

You are not signed in. Login or sign up in order to post.