//initial data string
$string = "one=1&two=2&three=3&four=4&two=2";
$results = array();
$data = explode('&', $string);
foreach($data as $param) {
$query = explode('=', $param);
$key = $query[0];
$value = $query[1];
// check to see if the key has been seen before.
// if not, store it in an array for now.
if(!isset($results[$key])){
$results[$key] = array($value);
}
else{
// the key is a duplicate, store it in the array
$results[$key][] = $value;
}
}
// implode the arrays so that they're in the $result = "2,2" format
foreach($data as $key => $value){
$data[$key] = implode(',', $value);
}
也有人提到过,但如果这是来自服务器帖子,那么您将不会获得重复的密钥。