3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = array("HIV", "Chlamydia", "Gonorrhoea"); $years = [ '2011' => false, '2012' => false, '2013' => false, '2014' => false, '2015' => false, '2016' => false, '2017' => false ]; $this_year = date('Y'); if (!array_key_exists($this_year, $years)) { // add to the array: $years[$this_year] = false; } $tests_by_year = []; $test_obj = []; $obj_count = count($years); $obj_added = 0; foreach ( $tests as $value ) { foreach ($years as $year => $yval) { $tests_by_year[$value][$year] = 0; if ($obj_added < $obj_count) { $test_obj[] = new \stdClass; } $test_obj[$obj_added]["y"] = (int) $year; $obj_added++; } } var_dump($test_obj); $test_obj2 = [ 0 => new \stdClass, 1 => new \stdClass, 2 => new \stdClass, 3 => new \stdClass, 4 => new \stdClass, 5 => new \stdClass, 6 => new \stdClass, 7 => new \stdClass, 8 => new \stdClass, 9 => new \stdClass ]; $test_obj2[0]->y = (int)2011; $test_obj2[1]->y = (int)2012; $test_obj2[2]->y = (int)2013; $test_obj2[3]->y = (int)2014; $test_obj2[4]->y = (int)2015; $test_obj2[5]->y = (int)2016; $test_obj2[6]->y = (int)2017; $test_obj2[7]->y = (int)2018; $test_obj2[8]->y = (int)2019; $test_obj2[9]->y = (int)2020; var_dump($test_obj2); /* foreach ($tests_by_year as $key => $value) { $test_obj[0]->$key = $value['2011']; $test_obj[1]->$key = $value['2012']; $test_obj[2]->$key = $value['2013']; $test_obj[3]->$key = $value['2014']; $test_obj[4]->$key = $value['2015']; $test_obj[5]->$key = $value['2016']; $test_obj[6]->$key = $value['2017']; $test_obj[7]->$key = $value['2018']; $test_obj[8]->$key = $value['2019']; $test_obj[9]->$key = $value['2020']; }*/
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 11
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 38
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 38
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 36
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 36
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 26, Position 2 = 30
Branch analysis from position: 26
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 30
Branch analysis from position: 36
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 36
Branch analysis from position: 38
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 38
Branch analysis from position: 11
filename:       /in/2Ldej
function name:  (null)
number of ops:  117
compiled vars:  !0 = $tests, !1 = $years, !2 = $this_year, !3 = $tests_by_year, !4 = $test_obj, !5 = $obj_count, !6 = $obj_added, !7 = $value, !8 = $yval, !9 = $year, !10 = $test_obj2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, <array>
   14     2        INIT_FCALL                                               'date'
          3        SEND_VAL                                                 'Y'
          4        DO_ICALL                                         $13     
          5        ASSIGN                                                   !2, $13
   16     6        ARRAY_KEY_EXISTS                                 ~15     !2, !1
          7        BOOL_NOT                                         ~16     ~15
          8      > JMPZ                                                     ~16, ->11
   19     9    >   ASSIGN_DIM                                               !1, !2
         10        OP_DATA                                                  <false>
   23    11    >   ASSIGN                                                   !3, <array>
   24    12        ASSIGN                                                   !4, <array>
   25    13        COUNT                                            ~20     !1
         14        ASSIGN                                                   !5, ~20
   26    15        ASSIGN                                                   !6, 0
   28    16      > FE_RESET_R                                       $23     !0, ->38
         17    > > FE_FETCH_R                                               $23, !7, ->38
   30    18    > > FE_RESET_R                                       $24     !1, ->36
         19    > > FE_FETCH_R                                       ~25     $24, !8, ->36
         20    >   ASSIGN                                                   !9, ~25
   32    21        FETCH_DIM_W                                      $27     !3, !7
         22        ASSIGN_DIM                                               $27, !9
         23        OP_DATA                                                  0
   34    24        IS_SMALLER                                               !6, !5
         25      > JMPZ                                                     ~29, ->30
   35    26    >   NEW                                              $31     'stdClass'
         27        DO_FCALL                                      0          
         28        ASSIGN_DIM                                               !4
         29        OP_DATA                                                  $31
   37    30    >   CAST                                          4  ~35     !9
         31        FETCH_DIM_W                                      $33     !4, !6
         32        ASSIGN_DIM                                               $33, 'y'
         33        OP_DATA                                                  ~35
   38    34        PRE_INC                                                  !6
   30    35      > JMP                                                      ->19
         36    >   FE_FREE                                                  $24
   28    37      > JMP                                                      ->17
         38    >   FE_FREE                                                  $23
   44    39        INIT_FCALL                                               'var_dump'
         40        SEND_VAR                                                 !4
         41        DO_ICALL                                                 
   46    42        NEW                                              $38     'stdClass'
         43        DO_FCALL                                      0          
         44        INIT_ARRAY                                       ~40     $38, 0
   47    45        NEW                                              $41     'stdClass'
         46        DO_FCALL                                      0          
         47        ADD_ARRAY_ELEMENT                                ~40     $41, 1
   48    48        NEW                                              $43     'stdClass'
         49        DO_FCALL                                      0          
         50        ADD_ARRAY_ELEMENT                                ~40     $43, 2
   49    51        NEW                                              $45     'stdClass'
         52        DO_FCALL                                      0          
         53        ADD_ARRAY_ELEMENT                                ~40     $45, 3
   50    54        NEW                                              $47     'stdClass'
         55        DO_FCALL                                      0          
         56        ADD_ARRAY_ELEMENT                                ~40     $47, 4
   51    57        NEW                                              $49     'stdClass'
         58        DO_FCALL                                      0          
         59        ADD_ARRAY_ELEMENT                                ~40     $49, 5
   52    60        NEW                                              $51     'stdClass'
         61        DO_FCALL                                      0          
         62        ADD_ARRAY_ELEMENT                                ~40     $51, 6
   53    63        NEW                                              $53     'stdClass'
         64        DO_FCALL                                      0          
         65        ADD_ARRAY_ELEMENT                                ~40     $53, 7
   54    66        NEW                                              $55     'stdClass'
         67        DO_FCALL                                      0          
         68        ADD_ARRAY_ELEMENT                                ~40     $55, 8
   55    69        NEW                                              $57     'stdClass'
         70        DO_FCALL                                      0          
         71        ADD_ARRAY_ELEMENT                                ~40     $57, 9
   45    72        ASSIGN                                                   !10, ~40
   58    73        CAST                                          4  ~62     2011
         74        FETCH_DIM_W                                      $60     !10, 0
         75        ASSIGN_OBJ                                               $60, 'y'
         76        OP_DATA                                                  ~62
   59    77        CAST                                          4  ~65     2012
         78        FETCH_DIM_W                                      $63     !10, 1
         79        ASSIGN_OBJ                                               $63, 'y'
         80        OP_DATA                                                  ~65
   60    81        CAST                                          4  ~68     2013
         82        FETCH_DIM_W                                      $66     !10, 2
         83        ASSIGN_OBJ                                               $66, 'y'
         84        OP_DATA                                                  ~68
   61    85        CAST                                          4  ~71     2014
         86        FETCH_DIM_W                                      $69     !10, 3
         87        ASSIGN_OBJ                                               $69, 'y'
         88        OP_DATA                                                  ~71
   62    89        CAST                                          4  ~74     2015
         90        FETCH_DIM_W                                      $72     !10, 4
         91        ASSIGN_OBJ                                               $72, 'y'
         92        OP_DATA                                                  ~74
   63    93        CAST                                          4  ~77     2016
         94        FETCH_DIM_W                                      $75     !10, 5
         95        ASSIGN_OBJ                                               $75, 'y'
         96        OP_DATA                                                  ~77
   64    97        CAST                                          4  ~80     2017
         98        FETCH_DIM_W                                      $78     !10, 6
         99        ASSIGN_OBJ                                               $78, 'y'
        100        OP_DATA                                                  ~80
   65   101        CAST                                          4  ~83     2018
        102        FETCH_DIM_W                                      $81     !10, 7
        103        ASSIGN_OBJ                                               $81, 'y'
        104        OP_DATA                                                  ~83
   66   105        CAST                                          4  ~86     2019
        106        FETCH_DIM_W                                      $84     !10, 8
        107        ASSIGN_OBJ                                               $84, 'y'
        108        OP_DATA                                                  ~86
   67   109        CAST                                          4  ~89     2020
        110        FETCH_DIM_W                                      $87     !10, 9
        111        ASSIGN_OBJ                                               $87, 'y'
        112        OP_DATA                                                  ~89
   69   113        INIT_FCALL                                               'var_dump'
        114        SEND_VAR                                                 !10
        115        DO_ICALL                                                 
   84   116      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.72 ms | 1404 KiB | 17 Q