我正在尝试使用数组推送在 Laravel 数组中添加新项目,但遇到了一些麻烦。我想在“data_chart”中添加名为“Color”的新项目。我已经尝试过使用数组 Push 和数组 Unshift。有没有更好的方法来做到这一点?
我想要这样的结果:
"data": [
{
"id": 29,
"title": "get data users",
"function_name": "selectDataUser",
"function_drop": "selectDataUser",
"type_of_chart": "Pie",
"embed": null,
"created_at": "2019-06-15 03:26:09.000",
"updated_at": null,
"data_chart": {
"data": [
{
"name": "Administrator",
"total": "100",
"color" "#9c1d1d" //I want color should be here in this line
},
{
"name": "Staff",
"total": "100",
"color" "#9c1d1d" //new item named Color
},
],
}
}
]
但是当我尝试使用数组推送时,结果变成了这样:
"data": [
{
"id": 29,
"title": "get data users",
"function_name": "selectDataUser",
"function_drop": "selectDataUser",
"type_of_chart": "Pie",
"embed": null,
"created_at": "2019-06-15 03:26:09.000",
"updated_at": null,
"data_chart": {
"data": [
{
"name": "Administrator",
"total": "100"
//color should be in here
},
{
"name": "Staff",
"total": "100"
//color should be in here
}
],
"color": "#9c1d1d" //idk but the color shouldn't like this
}
}
]
繁星coding
动漫人物