1 回答

TA貢獻1798條經驗 獲得超7個贊
您需要Riskdtls進一步創建一個數組,$insured_data['QuotaDtls']['Riskdtls']如下所示
$insured_data['Authenticate'] = [
'WACode' => '0000',
];
$insured_data['QuotaDtls'] = [
'ProductType'=> 'Individual'
];
$insured_data['QuotaDtls']['Riskdtls'][] = [
"InsuredName"=> "Testone",
"entry2"=> "testdata2",
"entry3"=> "testdata3"
];
$json = json_encode($insured_data,JSON_PRETTY_PRINT) ;
printf("<pre>%s</pre>", $json);
通過使用json_encode函數將數組編碼為 JSON 格式來實現所需的輸出,最終輸出如下:
{
"Authenticate": {
"WACode": "0000"
},
"QuotaDtls": {
"ProductType": "Individual",
"Riskdtls": [
{
"InsuredName": "Testone",
"entry2": "testdata2",
"entry3": "testdata3"
}
]
}
}
- 1 回答
- 0 關注
- 111 瀏覽
添加回答
舉報