3v4l.org

run code in 500+ PHP versions simultaneously
<?php $queryBalance=[ (object)["balance"=>"-257,21","id_month"=>12,"year"=>"2017"], (object)["balance"=>"-257,21","id_month"=>1,"year"=>"2018"], (object)["balance"=>"-257,21","id_month"=>2,"year"=>"2018"], (object)["balance"=>"166,66","id_month"=>3,"year"=>"2018"], (object)["balance"=>"55","id_month"=>12,"year"=>"2017"], //(object)["balance"=>"0","id_month"=>1,"year"=>"2018"], (object)["balance"=>"0","id_month"=>2,"year"=>"2018"], (object)["balance"=>"55","id_month"=>3,"year"=>"2018"], (object)["balance"=>"-22257,21","id_month"=>12,"year"=>"2017"], (object)["balance"=>"-64609,14","id_month"=>1,"year"=>"2018"], (object)["balance"=>"-64609,14","id_month"=>2,"year"=>"2018"], (object)["balance"=>"-12234,89","id_month"=>3,"year"=>"2018"] ]; foreach($queryBalance as $row){ $uniques[$row->year.'-'.$row->id_month]=NULL; // determine all unique date groups } while($queryBalance){ $temp=[]; foreach($uniques as $date=>$null){ $first=current($queryBalance); // cache the element that is currently first in $queryBalance $temp[]=($date==$first->year.'-'.$first->id_month) ? array_shift($queryBalance)->balance : NULL; // extract from array, or store NULL without modifying $queryBalance } $result[]=$temp; } var_export($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 78) Position 1 = 25, Position 2 = 32
Branch analysis from position: 25
1 jumps found. (Code = 42) Position 1 = 24
Branch analysis from position: 24
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 34
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 34
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 58
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 58
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 55
Branch analysis from position: 55
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 54
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 58
2 jumps found. (Code = 44) Position 1 = 62, Position 2 = 34
Branch analysis from position: 62
Branch analysis from position: 34
Branch analysis from position: 58
Branch analysis from position: 32
filename:       /in/DTKKI
function name:  (null)
number of ops:  66
compiled vars:  !0 = $queryBalance, !1 = $row, !2 = $uniques, !3 = $temp, !4 = $null, !5 = $date, !6 = $first, !7 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   CAST                                              8  ~8      <array>
          1        INIT_ARRAY                                           ~9      ~8
          2        CAST                                              8  ~10     <array>
          3        ADD_ARRAY_ELEMENT                                    ~9      ~10
          4        CAST                                              8  ~11     <array>
          5        ADD_ARRAY_ELEMENT                                    ~9      ~11
          6        CAST                                              8  ~12     <array>
          7        ADD_ARRAY_ELEMENT                                    ~9      ~12
          8        CAST                                              8  ~13     <array>
          9        ADD_ARRAY_ELEMENT                                    ~9      ~13
         10        CAST                                              8  ~14     <array>
         11        ADD_ARRAY_ELEMENT                                    ~9      ~14
         12        CAST                                              8  ~15     <array>
         13        ADD_ARRAY_ELEMENT                                    ~9      ~15
         14        CAST                                              8  ~16     <array>
         15        ADD_ARRAY_ELEMENT                                    ~9      ~16
         16        CAST                                              8  ~17     <array>
         17        ADD_ARRAY_ELEMENT                                    ~9      ~17
         18        CAST                                              8  ~18     <array>
         19        ADD_ARRAY_ELEMENT                                    ~9      ~18
         20        CAST                                              8  ~19     <array>
         21        ADD_ARRAY_ELEMENT                                    ~9      ~19
    2    22        ASSIGN                                                       !0, ~9
   16    23      > FE_RESET_R                                           $21     !0, ->32
         24    > > FE_FETCH_R                                                   $21, !1, ->32
   17    25    >   FETCH_OBJ_R                                          ~22     !1, 'year'
         26        CONCAT                                               ~23     ~22, '-'
         27        FETCH_OBJ_R                                          ~24     !1, 'id_month'
         28        CONCAT                                               ~25     ~23, ~24
         29        ASSIGN_DIM                                                   !2, ~25
         30        OP_DATA                                                      null
   16    31      > JMP                                                          ->24
         32    >   FE_FREE                                                      $21
   20    33      > JMP                                                          ->61
   21    34    >   ASSIGN                                                       !3, <array>
   22    35      > FE_RESET_R                                           $28     !2, ->58
         36    > > FE_FETCH_R                                           ~29     $28, !4, ->58
         37    >   ASSIGN                                                       !5, ~29
   23    38        INIT_FCALL                                                   'current'
         39        SEND_VAR                                                     !0
         40        DO_ICALL                                             $31     
         41        ASSIGN                                                       !6, $31
   24    42        FETCH_OBJ_R                                          ~34     !6, 'year'
         43        CONCAT                                               ~35     ~34, '-'
         44        FETCH_OBJ_R                                          ~36     !6, 'id_month'
         45        CONCAT                                               ~37     ~35, ~36
         46        IS_EQUAL                                                     !5, ~37
         47      > JMPZ                                                         ~38, ->54
         48    >   INIT_FCALL                                                   'array_shift'
         49        SEND_REF                                                     !0
         50        DO_ICALL                                             $39     
         51        FETCH_OBJ_R                                          ~40     $39, 'balance'
         52        QM_ASSIGN                                            ~41     ~40
         53      > JMP                                                          ->55
         54    >   QM_ASSIGN                                            ~41     null
         55    >   ASSIGN_DIM                                                   !3
         56        OP_DATA                                                      ~41
   22    57      > JMP                                                          ->36
         58    >   FE_FREE                                                      $28
   26    59        ASSIGN_DIM                                                   !7
         60        OP_DATA                                                      !3
   20    61    > > JMPNZ                                                        !0, ->34
   29    62    >   INIT_FCALL                                                   'var_export'
         63        SEND_VAR                                                     !7
         64        DO_ICALL                                                     
         65      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
167.31 ms | 2076 KiB | 16 Q