亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

修改php中的數組

修改php中的數組

PHP
慕容708150 2023-09-22 14:43:57
這是我創建數組的代碼$insured_data['QuotaDtls']['Riskdtls'] = [    "InsuredName"=> "Testone", ];$insured_data['Authenticate'] =   [    'WACode' => '0000',]; $insured_data['QuotaDtls'] = [    'ProductType'=> 'Individual'];Output:{   "Authenticate": {         "WACode": "0000",   },   "QuotaDtls": {         "ProductType": "Individual",         "Riskdtls": {                "InsuredName": "Testone",         }   }}我想對此數組進行一些修改,嘗試了許多不同的方法但無法做到。這是在代碼點火器中完成的,請幫忙。{   "Authenticate": {       "WACode": "0000"    },   "QuotaDtls": {       "ProductType": "Individual",       "Riskdtls": [                      {                          "InsuredName": "Testone",                      }        ]   }}
查看完整描述

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"

            }

        ]

    }

}


查看完整回答
反對 回復 2023-09-22
  • 1 回答
  • 0 關注
  • 111 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號