2013-03-01 48 views
0

我得到了下面的代碼,有沒有辦法像數組一樣工作?JSON與PHP一樣使用數組

$var = 
"{"uid":"cb463625fc9dde2d82207e15bde1b674513094011b2976.06073807","name":"marius"}{"uid":"2393d7a6a3258894acc34581978453fa513094011b2ab8.28630478","name":"buenyamin"}"; 

打印出來像

echo $var[0].uid."<br>"; 
echo $var[1].uid; 
+0

使用json_decode – cth 2013-03-01 11:48:25

回答

1

使用json_decode將字符串解碼爲PHP數組。

$var = 
"{"uid":"cb463625fc9dde2d82207e15bde1b674513094011b2976.06073807","name":"marius"}{"uid":"2393d7a6a3258894acc34581978453fa513094011b2ab8.28630478","name":"buenyamin"}"; 
echo '<pre>' . print_r(json_code($var, true)) . '</pre>';