Let’s say I have data string like this…
one=1&two=2&three=3&four=4&two=2
I’m using php foreach to grab the key/value and sort how I need it at this point
foreach($_POST as $key => $value) {
if ($key == "two") {
// $result = Take $value and add it to the previous $value .",";
}
}
The goal I am trying to reach is how do I take the duplicate keys and add the previous value generated in the loop. For example: The solution would be $result = 2,2,
If you’re
POSTing the string in the question to your server, you would only see one value oftwo, not both. The 2nd one would overwrite the first value.If you want multiple values for a key, you can make it an array by using
[].Now,
$_POST['two']will be an array (one,threeandfourwill be strings).