Associative array or list of variables from a string of name value pairs

I am trying to figure out how to divide a string of name value pairs into an associative array using php.

The format is:
&name=value&nextname=nextvalue
etc.

I have tried using explode(); with & as the separator
print_r (explode(“&”,$mystring));

and get
[0] =>name=value
[1] =>nextname=nextvalue

etc.

but what I am trying to do is get

[name]=>value
[nextname]=>nextvalue
etc.

any suggestions as to what php function or combination of functions will achieve this?

It would also be great to be able to do it as a list of variables.
$name = value;
$nextname = nextvalue;

thanks in advance for any suggestions.

Now take the result of explode() and explode() each of the resulting values on ‘=’.

Or you could just use [fphp]parse_str/fphp. :wink: