带有JSON的PHP`array_push`

问题描述 投票:0回答:1

我有一个json数组(名为$ourData),当前看起来像这样:

[
    //this item of $ourData named $officer_0
    {
        "code": "cg",
        "tots": [],
        "pds": []
    }
]

现在,如果我想将pushtots相关联的值(类似于"date" : "value",我该如何实现?

php
1个回答
1
投票
$data = json_decode($ourData, true);
$data['tots'][] = 'new data to add';
$ourData = json_encode($data);
© www.soinside.com 2019 - 2024. All rights reserved.