Explode string into array with key and value

徘徊边缘 提交于 2019-12-12 02:03:21

问题


I've a string like this:

$mystring = '{"1":"4","2":"2","3":"3"}';

I need to explode to something like this:

array(
  "1" => "4",
  "2" => "2",
  "3" => "3"
)

I use php 5.4.


回答1:


Just use json_decode.

$dd = json_decode($mystring, true);
var_export($dd);



回答2:


you "string" is very like json so maybe try json_decode()




回答3:


you should use the json decode function, your string looks like json. The second argument tells to make it as an array, not an object.

json_decode($mystring, true);


来源:https://stackoverflow.com/questions/27381807/explode-string-into-array-with-key-and-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!