How to create nested array from information received via POST

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 without success.

The information should 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);
}
    
asked by anonymous 06.01.2017 / 20:18

1 answer

2

If it is array do not need to string , do everything in array same:

$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 $arraySaida[] works similar to array_push() , a array within array of variable $arraySaida

    
06.01.2017 / 23:57