receive php$_POSTArray data

Asked 2 years ago, Updated 2 years ago, 87 views

value1=2012251&value1=2012254&value2=531&value2=544

I thought that if you attach the data in the above way and throw it, it will overlap and you can get it as an array, but when I actually did it, I only got the last value. I've tried many ways to receive it as an array, but I haven't found it yet. How should I get the price?

$arrValue1 = $_POST["value1"]; $arrValue2 = $_POST["value2"];

echo $arrValue1 2012251

echo $arrValue2 544

php get http

2022-09-21 14:36

2 Answers

Under

, such as html post, in name [ ], must be into a .

Date 1:<input name="date[]" type="text"><br>
Date 2:<input name="date[]" type="text"><br>
Date 3:<input name="date[]" type="text"><br>

If you read it as below, you will receive it as an array.

$email = $_POST['date'];   


2022-09-21 14:36

If you pass multiple values with the same key value, the value is already an array.

You can do it as follows.

$value1s = $_POST['value1'];
$value2s = $_POST['value2'];

// Try each one as follows.
foreach($value1s as $value) {
  print "Form value1 is ".$value."\n";
}
foreach($value2s as $value) {
  print "Form value2 is ".$value."\n";
}

// If value1 and value2 have the same number and need to be approached together, write as follows.
foreach( $value1 as $key => $val ) {
  print "Form value1 is "".$value"" and value2 is "".It is $value2s[$key].\n";
}

as above, for each the door, now available to view all the values.


2022-09-21 14:36

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.