2012-06-11 126 views
-1

我有一個字段格式:如何將數據放入數組中?

{"2G Network":"GSM 850","3G Network":"HSDPA 850"} 

如何將數據在陣列中的格式:

array(["2G Network"]=>"GSM 850", ["3G Network"]=>"HSDPA 850"); 

如何這個想法

+3

您正在尋找'json_decode()'。 – flowfree

+2

@bsdnoobz我認爲你的意思是'json_decode' –

+0

@AleksG是的,我編輯了我的評論。 – flowfree

回答

0
$text = '{"2G Network":"GSM 850","3G Network":"HSDPA 850"}'; 
$myArray = json_decode($text, true); 

用途:

echo $myArray['2G Network']; 
1

你想用json_decode()

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}'; 

var_dump(json_decode($json, true)); 

array(5) { 
    ["a"] => int(1) 
    ["b"] => int(2) 
    ["c"] => int(3) 
    ["d"] => int(4) 
    ["e"] => int(5) 
}