How to get a form input array into a PHP array

They are already in arrays: $name is an array, as is $email

So all you need to do is add a bit of processing to attack both arrays:

$name = $_POST['name'];
$email = $_POST['account'];

foreach( $name as $key => $n ) {
  print "The name is " . $n . " and email is " . $email[$key] . ", thank you\n";
}

To handle more inputs, just extend the pattern:

$name = $_POST['name'];
$email = $_POST['account'];
$location = $_POST['location'];

foreach( $name as $key => $n ) {
  print "The name is " . $n . ", email is " . $email[$key] .
        ", and location is " . $location[$key] . ". Thank you\n";
}

Leave a Comment