为了账号安全,请及时绑定邮箱和手机立即绑定

修改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 关注
  • 47 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信