3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = <<<JSON [ { "department": "CIS", "name": "Intro to CIS", "sections": [ { "sectionNumber": "01", "regNum": "012345", "days": "MWF", "startTime": "900", "endTime": "1030", "labDay": "M", "labStartTime": "1300", "labEndTime": "1500" }, { "sectionNumber": "02", "regNum": "098304", "days": "TR", "startTime": "1300", "endTime": "1500", "labDay": "", "labStartTime": "", "labEndTime": "" } ] }, { "department": "MATH", "name": "Intro to MATH", "sections": [ { "sectionNumber": "01", "regNum": "012345", "days": "MWF", "startTime": "900", "endTime": "1030", "labDay": "M", "labStartTime": "1300", "labEndTime": "1500" }, { "sectionNumber": "02", "regNum": "098304", "days": "TR", "startTime": "1300", "endTime": "1500", "labDay": "", "labStartTime": "", "labEndTime": "" } ] } ] JSON; $jsonArrayEntry = json_decode($data, true); function crossProduct() { $_ = func_get_args(); if (count($_) == 0) { return array(array()); } $a = array_shift($_); $c = call_user_func_array('crossProduct', $_); $r = array(); foreach ($a as $v) { foreach ($c as $p) { $r[] = array_merge(array($v), $p); } } return $r; } $allDepartmentsSections = []; foreach ($jsonArrayEntry as $entry) { $sections = []; foreach ($entry["sections"] as $section) { $sections[] = $section + [ "department" => $entry["department"], "name"=>$entry["name"] ]; } $allDepartmentsSections[] = $sections; } print_r(call_user_func_array('crossProduct', $allDepartmentsSections));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 25
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 25
Branch analysis from position: 9
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 21
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 21
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 21
Branch analysis from position: 25
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
filename:       /in/sSFpu
function name:  (null)
number of ops:  34
compiled vars:  !0 = $data, !1 = $jsonArrayEntry, !2 = $allDepartmentsSections, !3 = $entry, !4 = $sections, !5 = $section
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '%5B%0A++++%7B%0A++++++++%22department%22%3A+%22CIS%22%2C%0A++++++++%22name%22%3A+%22Intro+to+CIS%22%2C%0A++++++++%22sections%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22sectionNumber%22%3A+%2201%22%2C%0A++++++++++++++++%22regNum%22%3A+%22012345%22%2C%0A++++++++++++++++%22days%22%3A+%22MWF%22%2C%0A++++++++++++++++%22startTime%22%3A+%22900%22%2C%0A++++++++++++++++%22endTime%22%3A+%221030%22%2C%0A++++++++++++++++%22labDay%22%3A+%22M%22%2C%0A++++++++++++++++%22labStartTime%22%3A+%221300%22%2C%0A++++++++++++++++%22labEndTime%22%3A+%221500%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22sectionNumber%22%3A+%2202%22%2C%0A++++++++++++++++%22regNum%22%3A+%22098304%22%2C%0A++++++++++++++++%22days%22%3A+%22TR%22%2C%0A++++++++++++++++%22startTime%22%3A+%221300%22%2C%0A++++++++++++++++%22endTime%22%3A+%221500%22%2C%0A++++++++++++++++%22labDay%22%3A+%22%22%2C%0A++++++++++++++++%22labStartTime%22%3A+%22%22%2C%0A++++++++++++++++%22labEndTime%22%3A+%22%22%0A++++++++++++%7D%0A++++++++%5D%0A++++%7D%2C%0A++++%7B%0A++++++++%22department%22%3A+%22MATH%22%2C%0A++++++++%22name%22%3A+%22Intro+to+MATH%22%2C%0A++++++++%22sections%22%3A+%5B%0A++++++++++++%7B%0A++++++++++++++++%22sectionNumber%22%3A+%2201%22%2C%0A++++++++++++++++%22regNum%22%3A+%22012345%22%2C%0A++++++++++++++++%22days%22%3A+%22MWF%22%2C%0A++++++++++++++++%22startTime%22%3A+%22900%22%2C%0A++++++++++++++++%22endTime%22%3A+%221030%22%2C%0A++++++++++++++++%22labDay%22%3A+%22M%22%2C%0A++++++++++++++++%22labStartTime%22%3A+%221300%22%2C%0A++++++++++++++++%22labEndTime%22%3A+%221500%22%0A++++++++++++%7D%2C%0A++++++++++++%7B%0A++++++++++++++++%22sectionNumber%22%3A+%2202%22%2C%0A++++++++++++++++%22regNum%22%3A+%22098304%22%2C%0A++++++++++++++++%22days%22%3A+%22TR%22%2C%0A++++++++++++++++%22startTime%22%3A+%221300%22%2C%0A++++++++++++++++%22endTime%22%3A+%221500%22%2C%0A++++++++++++++++%22labDay%22%3A+%22%22%2C%0A++++++++++++++++%22labStartTime%22%3A+%22%22%2C%0A++++++++++++++++%22labEndTime%22%3A+%22%22%0A++++++++++++%7D%0A++++++++%5D%0A++++%7D%0A%5D'
   60     1        INIT_FCALL                                               'json_decode'
          2        SEND_VAR                                                 !0
          3        SEND_VAL                                                 <true>
          4        DO_ICALL                                         $7      
          5        ASSIGN                                                   !1, $7
   78     6        ASSIGN                                                   !2, <array>
   79     7      > FE_RESET_R                                       $10     !1, ->25
          8    > > FE_FETCH_R                                               $10, !3, ->25
   80     9    >   ASSIGN                                                   !4, <array>
   81    10        FETCH_DIM_R                                      ~12     !3, 'sections'
         11      > FE_RESET_R                                       $13     ~12, ->21
         12    > > FE_FETCH_R                                               $13, !5, ->21
   82    13    >   FETCH_DIM_R                                      ~15     !3, 'department'
         14        INIT_ARRAY                                       ~16     ~15, 'department'
         15        FETCH_DIM_R                                      ~17     !3, 'name'
         16        ADD_ARRAY_ELEMENT                                ~16     ~17, 'name'
         17        ADD                                              ~18     !5, ~16
         18        ASSIGN_DIM                                               !4
         19        OP_DATA                                                  ~18
   81    20      > JMP                                                      ->12
         21    >   FE_FREE                                                  $13
   84    22        ASSIGN_DIM                                               !2
         23        OP_DATA                                                  !4
   79    24      > JMP                                                      ->8
         25    >   FE_FREE                                                  $10
   87    26        INIT_FCALL                                               'print_r'
         27        INIT_FCALL                                               'crossproduct'
         28        SEND_ARRAY                                               !2
         29        CHECK_UNDEF_ARGS                                         
         30        DO_FCALL                                      1  $20     
         31        SEND_VAR                                                 $20
         32        DO_ICALL                                                 
         33      > RETURN                                                   1

Function crossproduct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 6
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 17, Position 2 = 30
Branch analysis from position: 17
2 jumps found. (Code = 78) Position 1 = 18, Position 2 = 30
Branch analysis from position: 18
2 jumps found. (Code = 77) Position 1 = 19, Position 2 = 28
Branch analysis from position: 19
2 jumps found. (Code = 78) Position 1 = 20, Position 2 = 28
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 19
Branch analysis from position: 19
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 17
Branch analysis from position: 17
Branch analysis from position: 28
Branch analysis from position: 30
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
filename:       /in/sSFpu
function name:  crossProduct
number of ops:  33
compiled vars:  !0 = $_, !1 = $a, !2 = $c, !3 = $r, !4 = $v, !5 = $p
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   63     0  E >   FUNC_GET_ARGS                                    ~6      
          1        ASSIGN                                                   !0, ~6
   64     2        COUNT                                            ~8      !0
          3        IS_EQUAL                                                 ~8, 0
          4      > JMPZ                                                     ~9, ->6
   65     5    > > RETURN                                                   <array>
   67     6    >   INIT_FCALL                                               'array_shift'
          7        SEND_REF                                                 !0
          8        DO_ICALL                                         $10     
          9        ASSIGN                                                   !1, $10
   68    10        INIT_USER_CALL                                0          'call_user_func_array', 'crossProduct'
         11        SEND_ARRAY                                               !0
         12        CHECK_UNDEF_ARGS                                         
         13        DO_FCALL                                      1  $12     
         14        ASSIGN                                                   !2, $12
   69    15        ASSIGN                                                   !3, <array>
   70    16      > FE_RESET_R                                       $15     !1, ->30
         17    > > FE_FETCH_R                                               $15, !4, ->30
   71    18    > > FE_RESET_R                                       $16     !2, ->28
         19    > > FE_FETCH_R                                               $16, !5, ->28
   72    20    >   INIT_FCALL                                               'array_merge'
         21        INIT_ARRAY                                       ~18     !4
         22        SEND_VAL                                                 ~18
         23        SEND_VAR                                                 !5
         24        DO_ICALL                                         $19     
         25        ASSIGN_DIM                                               !3
         26        OP_DATA                                                  $19
   71    27      > JMP                                                      ->19
         28    >   FE_FREE                                                  $16
   70    29      > JMP                                                      ->17
         30    >   FE_FREE                                                  $15
   75    31      > RETURN                                                   !3
   76    32*     > RETURN                                                   null

End of function crossproduct

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.58 ms | 1012 KiB | 18 Q