Array with variaves via POST

Asked

Viewed 39 times

0

My html is like this:

<input name='nDup[]' type='text'>
<input name='dVenc[]' type='text'>
<input name='vDup[]' type='text'>

Receiving this data via POST (which are the above inputs, can be repeated one or more times depending on the number of duplicates you have)

$nDup = $_POST['nDup'];
$dVenc = $_POST['nDup'];
$vDup = $_POST['nDup'];

I need to assemble a array same as this, with these POST values:

$aDup = array(
    array('carlos','2016-06-20','300.00'),
    array('mario','2016-07-20','300.00'),
    array('joao','2016-08-20','300.00'),
    array('silvio','2016-09-20','300.00')
);

Because I need to fill a foreach below with these values

foreach ($aDup as $dup) {
    $nDup = $dup[0];
    $dVenc = $dup[1];
    $vDup = $dup[2];
    $resp = $nfe->tagdup($nDup, $dVenc, $vDup);
}

I did it like this, I wonder if it’s right?

$nDup = $_POST['nDup'];
$dVenc = $_POST['nDup'];
$vDup = $_POST['nDup'];

$matrizDuplicata = array($nDup,$dVenc,$vDup);

foreach ($matrizDuplicata as $dup)
{
    $nDup = $dup[0];
    $dVenc = $dup[1];
    $vDup = $dup[2];
    $resp = $nfe->tagdup($nDup, $dVenc, $vDup);
}
  • From what you described in the question, the problem is exactly the same and the function array_map will solve, just pass as null the first parameter and the arrays in the other parameters, just as it was answered. If that’s not the problem, I recommend that you edit the question and try to make it clearer.

  • I’ll take the test. Thank you..

No answers

Browser other questions tagged

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