3v4l.org

run code in 300+ PHP versions simultaneously
<?php $configArray = array( 'grand_total' => array( 'after' => array(), 'before' => array(), '_code' => 'grand_total', ), 'discount' => array( 'after' => array(), 'before' => array('grand_total'), '_code' => 'discount', ), 'tax_subtotal' => array( 'after' => array( 0 => 'freeshipping', ), 'before' => array( 0 => 'tax', 1 => 'discount', ), '_code' => 'tax_subtotal', ), 'tax_shipping' => array( 'after' => array( 0 => 'shipping', 1 => 'tax_subtotal', ), 'before' => array( 0 => 'tax', 1 => 'discount', ), '_code' => 'tax_shipping', ), ); reset($configArray); $element = current($configArray); foreach ($configArray as $code => $data) { foreach ($data['before'] as $beforeCode) { if (!isset($configArray[$beforeCode])) { continue; } $configArray[$code]['before'] = array_unique( array_merge( $configArray[$code]['before'], $configArray[$beforeCode]['before'] ) ); $configArray[$beforeCode]['after'] = array_merge( $configArray[$beforeCode]['after'], array($code), $data['after'] ); $configArray[$beforeCode]['after'] = array_unique($configArray[$beforeCode]['after']); } foreach ($data['after'] as $afterCode) { if (!isset($configArray[$afterCode])) { continue; } $configArray[$code]['after'] = array_unique( array_merge( $configArray[$code]['after'], $configArray[$afterCode]['after'] ) ); $configArray[$afterCode]['before'] = array_merge( $configArray[$afterCode]['before'], array($code), $data['before'] ); $configArray[$afterCode]['before'] = array_unique($configArray[$afterCode]['before']); } } function compareTotals($a, $b) { $aCode = $a['_code']; $bCode = $b['_code']; if (in_array($aCode, $b['after']) || in_array($bCode, $a['before'])) { $res = -1; } elseif (in_array($bCode, $a['after']) || in_array($aCode, $b['before'])) { $res = 1; } else { $res = 0; } return $res; } uasort($configArray, 'compareTotals'); print_r(array_keys($configArray));
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 98
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 98
Branch analysis from position: 10
2 jumps found. (Code = 77) Position 1 = 13, Position 2 = 53
Branch analysis from position: 13
2 jumps found. (Code = 78) Position 1 = 14, Position 2 = 53
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 17, Position 2 = 18
Branch analysis from position: 17
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 13
Branch analysis from position: 13
Branch analysis from position: 53
2 jumps found. (Code = 77) Position 1 = 56, Position 2 = 96
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 96
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 61
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 96
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 96
Branch analysis from position: 53
Branch analysis from position: 98
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 98
filename:       /in/udaKl
function name:  (null)
number of ops:  110
compiled vars:  !0 = $configArray, !1 = $element, !2 = $data, !3 = $code, !4 = $beforeCode, !5 = $afterCode
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   43     1        INIT_FCALL                                               'reset'
          2        SEND_REF                                                 !0
          3        DO_ICALL                                                 
   44     4        INIT_FCALL                                               'current'
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !1, $8
   45     8      > FE_RESET_R                                       $10     !0, ->98
          9    > > FE_FETCH_R                                       ~11     $10, !2, ->98
         10    >   ASSIGN                                                   !3, ~11
   46    11        FETCH_DIM_R                                      ~13     !2, 'before'
         12      > FE_RESET_R                                       $14     ~13, ->53
         13    > > FE_FETCH_R                                               $14, !4, ->53
   47    14    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~15     !0, !4
         15        BOOL_NOT                                         ~16     ~15
         16      > JMPZ                                                     ~16, ->18
   48    17    > > JMP                                                      ->13
   50    18    >   INIT_FCALL                                               'array_unique'
   51    19        INIT_FCALL                                               'array_merge'
   52    20        FETCH_DIM_R                                      ~19     !0, !3
         21        FETCH_DIM_R                                      ~20     ~19, 'before'
         22        SEND_VAL                                                 ~20
   53    23        FETCH_DIM_R                                      ~21     !0, !4
         24        FETCH_DIM_R                                      ~22     ~21, 'before'
         25        SEND_VAL                                                 ~22
         26        DO_ICALL                                         $23     
         27        SEND_VAR                                                 $23
         28        DO_ICALL                                         $24     
   50    29        FETCH_DIM_W                                      $17     !0, !3
         30        ASSIGN_DIM                                               $17, 'before'
   53    31        OP_DATA                                                  $24
   56    32        INIT_FCALL                                               'array_merge'
   57    33        FETCH_DIM_R                                      ~27     !0, !4
         34        FETCH_DIM_R                                      ~28     ~27, 'after'
         35        SEND_VAL                                                 ~28
   58    36        INIT_ARRAY                                       ~29     !3
         37        SEND_VAL                                                 ~29
   59    38        FETCH_DIM_R                                      ~30     !2, 'after'
         39        SEND_VAL                                                 ~30
         40        DO_ICALL                                         $31     
   56    41        FETCH_DIM_W                                      $25     !0, !4
         42        ASSIGN_DIM                                               $25, 'after'
   59    43        OP_DATA                                                  $31
   61    44        INIT_FCALL                                               'array_unique'
         45        FETCH_DIM_R                                      ~34     !0, !4
         46        FETCH_DIM_R                                      ~35     ~34, 'after'
         47        SEND_VAL                                                 ~35
         48        DO_ICALL                                         $36     
         49        FETCH_DIM_W                                      $32     !0, !4
         50        ASSIGN_DIM                                               $32, 'after'
         51        OP_DATA                                                  $36
   46    52      > JMP                                                      ->13
         53    >   FE_FREE                                                  $14
   63    54        FETCH_DIM_R                                      ~37     !2, 'after'
         55      > FE_RESET_R                                       $38     ~37, ->96
         56    > > FE_FETCH_R                                               $38, !5, ->96
   64    57    >   ISSET_ISEMPTY_DIM_OBJ                         0  ~39     !0, !5
         58        BOOL_NOT                                         ~40     ~39
         59      > JMPZ                                                     ~40, ->61
   65    60    > > JMP                                                      ->56
   67    61    >   INIT_FCALL                                               'array_unique'
   68    62        INIT_FCALL                                               'array_merge'
   69    63        FETCH_DIM_R                                      ~43     !0, !3
         64        FETCH_DIM_R                                      ~44     ~43, 'after'
         65        SEND_VAL                                                 ~44
   70    66        FETCH_DIM_R                                      ~45     !0, !5
         67        FETCH_DIM_R                                      ~46     ~45, 'after'
         68        SEND_VAL                                                 ~46
         69        DO_ICALL                                         $47     
         70        SEND_VAR                                                 $47
         71        DO_ICALL                                         $48     
   67    72        FETCH_DIM_W                                      $41     !0, !3
         73        ASSIGN_DIM                                               $41, 'after'
   70    74        OP_DATA                                                  $48
   73    75        INIT_FCALL                                               'array_merge'
   74    76        FETCH_DIM_R                                      ~51     !0, !5
         77        FETCH_DIM_R                                      ~52     ~51, 'before'
         78        SEND_VAL                                                 ~52
   75    79        INIT_ARRAY                                       ~53     !3
         80        SEND_VAL                                                 ~53
   76    81        FETCH_DIM_R                                      ~54     !2, 'before'
         82        SEND_VAL                                                 ~54
         83        DO_ICALL                                         $55     
   73    84        FETCH_DIM_W                                      $49     !0, !5
         85        ASSIGN_DIM                                               $49, 'before'
   76    86        OP_DATA                                                  $55
   78    87        INIT_FCALL                                               'array_unique'
         88        FETCH_DIM_R                                      ~58     !0, !5
         89        FETCH_DIM_R                                      ~59     ~58, 'before'
         90        SEND_VAL                                                 ~59
         91        DO_ICALL                                         $60     
         92        FETCH_DIM_W                                      $56     !0, !5
         93        ASSIGN_DIM                                               $56, 'before'
         94        OP_DATA                                                  $60
   63    95      > JMP                                                      ->56
         96    >   FE_FREE                                                  $38
   45    97      > JMP                                                      ->9
         98    >   FE_FREE                                                  $10
   96    99        INIT_FCALL                                               'uasort'
        100        SEND_REF                                                 !0
        101        SEND_VAL                                                 'compareTotals'
        102        DO_ICALL                                                 
   98   103        INIT_FCALL                                               'print_r'
        104        INIT_FCALL                                               'array_keys'
        105        SEND_VAR                                                 !0
        106        DO_ICALL                                         $62     
        107        SEND_VAR                                                 $62
        108        DO_ICALL                                                 
        109      > RETURN                                                   1

Function comparetotals:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 47) Position 1 = 12, Position 2 = 18
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 21
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
2 jumps found. (Code = 47) Position 1 = 27, Position 2 = 33
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 36
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 33
Branch analysis from position: 18
filename:       /in/udaKl
function name:  compareTotals
number of ops:  39
compiled vars:  !0 = $a, !1 = $b, !2 = $aCode, !3 = $bCode, !4 = $res
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   82     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   84     2        FETCH_DIM_R                                      ~5      !0, '_code'
          3        ASSIGN                                                   !2, ~5
   85     4        FETCH_DIM_R                                      ~7      !1, '_code'
          5        ASSIGN                                                   !3, ~7
   86     6        INIT_FCALL                                               'in_array'
          7        SEND_VAR                                                 !2
          8        FETCH_DIM_R                                      ~9      !1, 'after'
          9        SEND_VAL                                                 ~9
         10        DO_ICALL                                         $10     
         11      > JMPNZ_EX                                         ~11     $10, ->18
         12    >   INIT_FCALL                                               'in_array'
         13        SEND_VAR                                                 !3
         14        FETCH_DIM_R                                      ~12     !0, 'before'
         15        SEND_VAL                                                 ~12
         16        DO_ICALL                                         $13     
         17        BOOL                                             ~11     $13
         18    > > JMPZ                                                     ~11, ->21
   87    19    >   ASSIGN                                                   !4, -1
         20      > JMP                                                      ->37
   88    21    >   INIT_FCALL                                               'in_array'
         22        SEND_VAR                                                 !3
         23        FETCH_DIM_R                                      ~15     !0, 'after'
         24        SEND_VAL                                                 ~15
         25        DO_ICALL                                         $16     
         26      > JMPNZ_EX                                         ~17     $16, ->33
         27    >   INIT_FCALL                                               'in_array'
         28        SEND_VAR                                                 !2
         29        FETCH_DIM_R                                      ~18     !1, 'before'
         30        SEND_VAL                                                 ~18
         31        DO_ICALL                                         $19     
         32        BOOL                                             ~17     $19
         33    > > JMPZ                                                     ~17, ->36
   89    34    >   ASSIGN                                                   !4, 1
         35      > JMP                                                      ->37
   91    36    >   ASSIGN                                                   !4, 0
   93    37    > > RETURN                                                   !4
   94    38*     > RETURN                                                   null

End of function comparetotals

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.74 ms | 1400 KiB | 29 Q