3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( '2013-07-19' => 1, '2013-07-21' => 3, '2013-07-23' => 2, '2013-07-24' => 4, '2013-07-25' => 4, '2013-07-26' => 2, '2013-07-27' => 2, '2013-07-30' => 3, '2013-07-31' => 1 ); $result = array(); $ref = new DateTime('1821-11-11'); // or starting with PHP 7.3: $ref = new DateTime(array_key_first($data)); foreach ($data as $datum => $nb) { //if ($ref->add($oneDay)->format('Y-m-d') !== $datum) { if ($ref->modify('+1 day')->format('Y-m-d') !== $datum) { $result[] = array(); $ref->setDate(...explode('-', $datum));// = new DateTime($datum); } $result[count($result) - 1][$datum] = $nb; } print_r($result);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 33
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 33
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 27
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 27
Branch analysis from position: 33
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
filename:       /in/lF6Jb
function name:  (null)
number of ops:  38
compiled vars:  !0 = $data, !1 = $result, !2 = $ref, !3 = $nb, !4 = $datum
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   15     1        ASSIGN                                                   !1, <array>
   16     2        NEW                                              $7      'DateTime'
          3        SEND_VAL_EX                                              '1821-11-11'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !2, $7
   18     6      > FE_RESET_R                                       $10     !0, ->33
          7    > > FE_FETCH_R                                       ~11     $10, !3, ->33
          8    >   ASSIGN                                                   !4, ~11
   20     9        INIT_METHOD_CALL                                         !2, 'modify'
         10        SEND_VAL_EX                                              '%2B1+day'
         11        DO_FCALL                                      0  $13     
         12        INIT_METHOD_CALL                                         $13, 'format'
         13        SEND_VAL_EX                                              'Y-m-d'
         14        DO_FCALL                                      0  $14     
         15        IS_NOT_IDENTICAL                                         !4, $14
         16      > JMPZ                                                     ~15, ->27
   21    17    >   ASSIGN_DIM                                               !1
         18        OP_DATA                                                  <array>
   22    19        INIT_METHOD_CALL                                         !2, 'setDate'
         20        INIT_FCALL                                               'explode'
         21        SEND_VAL                                                 '-'
         22        SEND_VAR                                                 !4
         23        DO_ICALL                                         $17     
         24        SEND_UNPACK                                              $17
         25        CHECK_UNDEF_ARGS                                         
         26        DO_FCALL                                      1          
   25    27    >   COUNT                                            ~19     !1
         28        SUB                                              ~20     ~19, 1
         29        FETCH_DIM_W                                      $21     !1, ~20
         30        ASSIGN_DIM                                               $21, !4
         31        OP_DATA                                                  !3
   18    32      > JMP                                                      ->7
         33    >   FE_FREE                                                  $10
   28    34        INIT_FCALL                                               'print_r'
         35        SEND_VAR                                                 !1
         36        DO_ICALL                                                 
         37      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.03 ms | 1012 KiB | 15 Q