Reputation: 49
If I have a example string like this: "dataset1"=>"blank","gdataset"=>"f1,f2"
I'm trying to create an array of the key/value pairs. Desired array result should look like this:
Array(
[0] => "dataset1"=>"blank"
[1] => "gdataset"=>"f1,f2"
)
I've tried http_build_query & explode w/o success, as the array key or value is getting mangled.
What should I use to get the desired array?
Upvotes: 0
Views: 24
Reputation: 79024
It's kind of hackish, but just replace ","
with "",""
to keep the quotes and then explode on ","
:
$result = explode('","', str_replace('","', '"",""', $string));
But I'm positive that there is a much better way to do whatever you are doing in general. Maybe a new question outlining why you are doing this?
Upvotes: 1