Skip to content

Instantly share code, notes, and snippets.

@mgiacomini
Created June 6, 2013 21:14
Show Gist options
  • Save mgiacomini/5725016 to your computer and use it in GitHub Desktop.
Save mgiacomini/5725016 to your computer and use it in GitHub Desktop.
$str = "key1=value1&key2=value2&key2=value3&key3=value4";
$params = explode("&", $str);
$output = array();
foreach ($params as $param){
$param = explode("=", $param);
$key = $param[0];
$value = $param[1];
if(array_key_exists($key, $output))
$output[$key] = array_merge( (array)$output[$key], (array)$value );
else
$output[$key] = $value;
}
print_r($output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment