2016-09-22 141 views
0

我試圖創建一個JSON字符串,看起來像這樣創建JSON對象:與陣列陣列屬性在PHP

{"id":"1","name":"new group test","beschreibung":"this is a description","gewerbe":"1" , "members":[{"uniqueid":"100110001"},{"uniqueid":"100110002"},{"uniqueid":"100110003"}]} 

現在我的輸出看起來是這樣的:

{"data":{"id":"1","name":"new group test","beschreibung":"this is a ne","gewerbe":"1"},"members":[{"uniqueid":"100110001"},{"uniqueid":"100110002"},{"uniqueid":"100110003"}]} 

使用以下PHP代碼:

return array('data' => $data, 'members' => $members); 

$ data是SQL查詢的結果,$ members是另一個SQL查詢的結果數組。我希望將我的成員數組作爲數據內的屬性,就像我發佈的示例中那樣。我如何創建這樣的字符串?陣列的

回答

2
$data['members'] = $members; 
return json_encode($data); 
0

更改結構:

代替

json_encode(array('data' => $data, 'members' => $members)); 

使用:

$data['members'] = $members; 
json_encode($data);