<?php
$array = [
'2015-09-23' => [
'user' => [13, 12],
'count' => [
'count' => 2,
'total' => 2,
],
],
'2015-09-24' => [
'user' => [14],
'count' => [
'count' => 1,
'total' => 1,
],
],
'2015-09-25' => [
'user' => [15],
'count' => [
'count' => 1,
'total' => 1,
],
],
'2015-09-26' => [
'user' => [16],
'count' => [
'count' => 1,
'total' => 1,
],
],
'2015-09-27' => [
'user' => [17, 18],
'count' => [
'count' => 2,
'total' => 2,
],
],
'2015-09-28' => [
'user' => [19, 20, 21, 22, 23, 24, 25, 26, 27, 28],
'count' => [
'count' => 10,
'total' => 10,
],
],
];
var_export(
array_map(
function ($set) {
static $prev = 0;
$prev = $set['count']['total'] += $prev;
return $set;
},
$array
)
);
- Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
- array (
'2015-09-23' =>
array (
'user' =>
array (
0 => 13,
1 => 12,
),
'count' =>
array (
'count' => 2,
'total' => 2,
),
),
'2015-09-24' =>
array (
'user' =>
array (
0 => 14,
),
'count' =>
array (
'count' => 1,
'total' => 3,
),
),
'2015-09-25' =>
array (
'user' =>
array (
0 => 15,
),
'count' =>
array (
'count' => 1,
'total' => 4,
),
),
'2015-09-26' =>
array (
'user' =>
array (
0 => 16,
),
'count' =>
array (
'count' => 1,
'total' => 5,
),
),
'2015-09-27' =>
array (
'user' =>
array (
0 => 17,
1 => 18,
),
'count' =>
array (
'count' => 2,
'total' => 7,
),
),
'2015-09-28' =>
array (
'user' =>
array (
0 => 19,
1 => 20,
2 => 21,
3 => 22,
4 => 23,
5 => 24,
6 => 25,
7 => 26,
8 => 27,
9 => 28,
),
'count' =>
array (
'count' => 10,
'total' => 17,
),
),
)
preferences:
46.96 ms | 404 KiB | 62 Q