2 回答

TA贡献1784条经验 获得超8个赞
您可以迭代您的数组,使用array_merge
splat运算符...
来展平内部数组。请注意,数组中不能有两个DateUser
键,因此将删除一个;假设它们具有与您的数据相同的值,这不会成为问题:
$array = array (
'Apr-2019' =>
array (
0 =>
array (
'DateUser' => 'Apr-2019',
'withdarw_amount' => 4.00
),
1 =>
array (
'current_deposit_amount' => 1.00,
'current_deposit_table_refer' => 0.00,
'current_deposit_user_refer' => 0.10,
'DateUser' => 'Apr-2019'
),
),
'Jun-2019' =>
array (
0 =>
array (
'DateUser' => 'Jun-2019',
'withdarw_amount' => 334.00
),
)
);
foreach ($array as &$arr) {
$arr = array_merge(...$arr);
}
print_r($array);
输出:
Array
(
[Apr-2019] => Array
(
[DateUser] => Apr-2019
[withdarw_amount] => 4
[current_deposit_amount] => 1
[current_deposit_table_refer] => 0
[current_deposit_user_refer] => 0.1
)
[Jun-2019] => Array
(
[DateUser] => Jun-2019
[withdarw_amount] => 334
)
)

TA贡献1876条经验 获得超7个赞
您也可以使用简单的循环来做到这一点 -
$new = [];
foreach ($array as $key =>$a) {
$new[$key] = []; // Define with key
foreach ($a as $v) {
$new[$key] += $v; // Concat
}
}
- 2 回答
- 0 关注
- 130 浏览
添加回答
举报