Skip to content
Advertisement

Retrieve post array values

I have a form that sends all the data with jQuery .serialize() In the form are four arrays qty[], etc it send the form data to a sendMail page and I want to get the posted data back out of the arrays.

I have tried:

$qty = $_POST['qty[]'];
foreach($qty as $value)
{
  $qtyOut = $value . "<br>";
}

And tried this:

for($q=0;$q<=$qty;$q++)
{
 $qtyOut = $q . "<br>";
}

Is this the correct approach?

Advertisement

Answer

You have [] within your $_POST variable – these aren’t required. You should use:

$qty = $_POST['qty'];

Your code would then be:

$qty = $_POST['qty'];

foreach($qty as $value) {

   $qtyOut = $value . "<br>";

}

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement