Is there an already existing function in PHP for creating an associative array from a delimited string? If not, what would be the most effective means of doing so? I am looking at PayPal's new NVP API, where requests and responses have the following format:
method=blah&name=joe&id=joeuser&age=33&stuff=junk
I can use explode()
to get each pair into an array value, but it would be even better if I could do some sort of function like dictionary_explode
and indicate the key-value delimiter and get back an associate array like:
Array {
[method] => blah
[name] => joe
[id] => joeuser
[age] => 33
[stuff] => junk
}
My CS friends tell me that this idea exists in other languages like Python, so I'm wondering if I just haven't found such a thing for PHP. Right now I'm looking at doing an array_walk, but I'd prefer something more pre-built.