如何将新属性添加到存储在 mysql 表列中的 json 对象?现在我将 json_encode 数据存储为:
"1":{"lastname":"blah","firstname":"R.A.","function":"Manager","email":"test@hotmail.com","barcode":"33432799181"}
我想添加一个新的数据对,visted:0,一旦有人被访问,我想更新它。
"1":{"lastname":"blah","firstname":"R.A.","function":"Manager","email":"test@hotmail.com","barcode":"33432799181", "visited":"0"}
如何将元素推送到现有的 json 数据?
$jsondataTmp = json_decode($core,true);
$custom = array('visited'=>'0');
$jsondataTmp[] = $custom;
但它添加了一个数组而不是每个数组
[1] => Array
(
[lastname] => blah
[firstname] => R.A.
[function] => Manager
[email] => test@hotmail.com
[barcode] => 33432799181
)
[2] => Array
(
[lastname] => blah
[firstname] => R.A.
[function] => Manager
[email] => test@hotmail.com
[barcode] => 33432799181
)
[3] => Array
(
[visited] => 0
)
并不是
[2] => Array
(
[lastname] => blah
[firstname] => R.A.
[function] => Manager
[email] => test@hotmail.com
[barcode] => 33432799181
[visited] => 0
)