I have a string that when I var_dump returns the following
string(20) "{\"key1\":\"key1_value",\"key2\":\"key2_value\"}"
How can I convert that into an array that will return the following when I var_dump?
array(2) { ["key1"]=> string(20) "key1_value" ["key2"]=> string(20) "key2_value" }
Thanks,
Tee
What you have as data looks like valid JSON. You probably can use json_decode with the second parameter to true (to get an associative array) like this:
It looks like a simple JSON array that got mangled by PHP's
magic_quotes
or some other escaping function. Turn offmagic_quotes
and runjson_decode()
on the string.The explode function will get you what you need.
should do the trick.