<?php
$array = [
['amount' => 13.31000000, 'i' => 1, 'created_at' => '2022-10-10 23:21:47',],
['amount' => 19.00000000, 'i' => 2, 'created_at' => '2022-10-10 23:21:38',],
['amount' => 17.32000000, 'i' => 2, 'created_at' => '2022-10-09 23:21:47',],
['amount' => 19.15000000, 'i' => 2, 'created_at' => '2022-10-08 23:21:47',],
['amount' => 14.68000000, 'i' => 2, 'created_at' => '2022-10-07 23:21:47',],
['amount' => 18.31000000, 'i' => 2, 'created_at' => '2022-10-06 23:21:47',],
['amount' => 19.48000000, 'i' => 2, 'created_at' => '2022-10-05 23:21:47',],
['amount' => 11.20000000, 'i' => 1, 'created_at' => '2022-10-04 23:21:47',],
['amount' => 12.91000000, 'i' => 2, 'created_at' => '2022-10-03 23:21:47',],
['amount' => 11.55000000, 'i' => 2, 'created_at' => '2022-10-02 23:21:47',],
['amount' => 13.64000000, 'i' => 1, 'created_at' => '2022-10-09 23:21:38',],
['amount' => 18.44000000, 'i' => 1, 'created_at' => '2022-10-08 23:21:38',],
['amount' => 11.56000000, 'i' => 2, 'created_at' => '2022-10-07 23:21:38',],
['amount' => 12.13000000, 'i' => 1, 'created_at' => '2022-10-06 23:21:38',],
['amount' => 13.39000000, 'i' => 1, 'created_at' => '2022-10-05 23:21:38',],
['amount' => 11.36000000, 'i' => 2, 'created_at' => '2022-10-04 23:21:38',],
['amount' => 11.82000000, 'i' => 1, 'created_at' => '2022-10-03 23:21:38',],
['amount' => 14.03000000, 'i' => 1, 'created_at' => '2022-10-02 23:21:38',],
];
const LOOKUP = [1 => 'increase', 2 => 'decrease'];
$defaults = array_fill_keys(LOOKUP, 0);
$result = [];
foreach ($array as $row) {
$date = substr($row['created_at'], 0, 10);
$result[$date] ??= $defaults;
$result[$date][LOOKUP[$row['i']]] += $row['amount'];
}
print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 32
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 32
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 32
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 32
filename: /in/1lZHa
function name: (null)
number of ops: 37
compiled vars: !0 = $array, !1 = $defaults, !2 = $result, !3 = $row, !4 = $date
line #* E I O op fetch ext return operands
-------------------------------------------------------------------------------------
3 0 E > ASSIGN !0, <array>
24 1 DECLARE_CONST 'LOOKUP', <array>
25 2 INIT_FCALL 'array_fill_keys'
3 FETCH_CONSTANT ~6 'LOOKUP'
4 SEND_VAL ~6
5 SEND_VAL 0
6 DO_ICALL $7
7 ASSIGN !1, $7
27 8 ASSIGN !2, <array>
28 9 > FE_RESET_R $10 !0, ->32
10 > > FE_FETCH_R $10, !3, ->32
29 11 > INIT_FCALL 'substr'
12 FETCH_DIM_R ~11 !3, 'created_at'
13 SEND_VAL ~11
14 SEND_VAL 0
15 SEND_VAL 10
16 DO_ICALL $12
17 ASSIGN !4, $12
30 18 FETCH_DIM_IS ~14 !2, !4
19 COALESCE ~15 ~14
20 ASSIGN_DIM ~16 !2, !4
21 OP_DATA !1
22 QM_ASSIGN ~15 ~16
23 FREE ~15
31 24 FETCH_CONSTANT ~18 'LOOKUP'
25 FETCH_DIM_R ~19 !3, 'i'
26 FETCH_DIM_R ~20 ~18, ~19
27 FETCH_DIM_R ~22 !3, 'amount'
28 FETCH_DIM_RW $17 !2, !4
29 ASSIGN_DIM_OP += 1 $17, ~20
30 OP_DATA ~22
28 31 > JMP ->10
32 > FE_FREE $10
34 33 INIT_FCALL 'print_r'
34 SEND_VAR !2
35 DO_ICALL
36 > RETURN 1
Generated using Vulcan Logic Dumper, using php 8.0.0
preferences:
135.48 ms | 1003 KiB | 16 Q