2012-05-07 82 views
1

我有一個JS腳本,即時通訊的代碼轉換到PHP,但我堅持的正確語法是創建與此相同的代碼在JS在我的PHP腳本是什麼:設置PHP語法一個變量

var sdata = { 
      "13":{ 
       "22":["618","22","1","1","0","0","0"], 
       "21":["617","22","1","1","0","0","0"] 
      },    
      "14":{ 
       "22":["619","22","1","1","0","0","0"], 
       "20":["622","22","1","1","0","0","0"] 
      },  
      "15":{ 
       "20":["623","22","1","1","0","0","0"] 
    } 
}; 

有什麼想法?

+1

如果你想在同一對象轉換在PHP然後使用http://www.php。 net/manual/en/function.json-decode.php,否則請參閱mata的答案。 –

+0

包裝是一個對象,第一個層次也是對象,他們的子元素是數組。你想要完全相同的結構,還是隻想讓數據層保持一致? –

+0

@tpaksu我想它像馬塔回答:)我不解析變量的結果 - 我正在重寫整個腳本:) – Sir

回答

2
$sdata = array(
      "13" => array(
       "22" => array("618","22","1","1","0","0","0"), 
       "21" => array("617","22","1","1","0","0","0") 
      ),    
      "14" => array(
       "22" => array("619","22","1","1","0","0","0"), 
       "20" => array("622","22","1","1","0","0","0") 
      ),  
      "15" => array(
       "20" => array("623","22","1","1","0","0","0") 
    ) 
); 
+0

啊,我看到謝謝!畢竟非常相似! – Sir

2

要做的最簡單的事情就是使用jQuery .get函數,將此數組作爲數據的一部分發送,然後在$ _GET變量上運行PHP函數json_decode以獲取PHP數組:)然後,如果需要對數組進行硬編碼,則可以print_r數組。

+0

是真的,但我認爲他們正在尋找實際的編碼過程 - 不消耗JSON –

+0

嗯,我的想法是消費JSON,然後回顯PHP數組。這樣,您可以通過手動方式排除任何錯誤。 – Ansari