How can I turn a string below into an array?
pg_id=2&parent_id=2&document&video
This is the array I am looking for,
array(
'pg_id' => 2,
'parent_id' => 2,
'document' => ,
'video' =>
)
How can I turn a string below into an array?
pg_id=2&parent_id=2&document&video
This is the array I am looking for,
array(
'pg_id' => 2,
'parent_id' => 2,
'document' => ,
'video' =>
)
This is one-liner for parsing query from current URL into array:
For this specific question the chosen answer is correct but if there is a redundant parameter—like an extra "e"—in the URL the function will silently fail without an error or exception being thrown:
So I prefer using my own parser like so:
Now you have all the occurrences of each parameter in its own array, you can always merge them into one array if you want to.
Hope that helps!
You want the
parse_str
function, and you need to set the second parameter to have the data put in an array instead of into individual variables.