将字符串分解为具有键和值的数组


Explode string into array with key and value

我有一个这样的字符串:

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

我需要爆炸成这样:

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

我使用 php 5.4。

只需使用 json_decode .

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

你的"string"非常像json,所以也许可以尝试json_decode()

你应该使用json解码函数,你的字符串看起来像json。第二个参数告诉它使其成为数组,而不是对象。

json_decode($mystring, true);