Retrieve post array values

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>";

}

php automatically detects $_POST and $_GET-arrays so you can juse:

<form method="post">
    <input value="user1"  name="qty[]" type="checkbox">
    <input value="user2"  name="qty[]" type="checkbox">
    <input type="submit">
</form>

<?php
$qty = $_POST['qty'];

and $qty will by a php-Array. Now you can access it by:

if (is_array($qty))
{
  for ($i=0;$i<size($qty);$i++)
  {
    print ($qty[$i]);
  }
}
?>

if you are not sure about the format of the received data structure you can use:

print_r($_POST['qty']);

or even

print_r($_POST);

to see how it is stored.

Tags:

Php

Arrays

Jquery