3v4l.org

run code in 500+ PHP versions simultaneously
<?php $in = array('e1','e2','e3','e4'); //$new =[]; $count = count($in); Foreach($in as $key => $val){ $new[] = $val; // add first value // loop through in to greate the long incrementing string For($i=$key; $i<=$count-$key;$i++){ if($key != 0){ $new[] = implode("-",array_slice($in,$key,$i)); }else{ if($i - $key>1) $new[] = implode("-",array_slice($in,$key,$i)); } } // all but second to last except if iteration has come to far if($count-2-$key >1) $new[] = Implode("-",Array_slice($in,$key,$count-2)). "-". $in[$count-1]; // $key (skip one) next one. except if iteration has come to far If($count-2-$key >1) $new[] = $in[$key] . "-" . $in[$key+2]; // $key (skip one) rest of array except if iteration has come to far if($count-2-$key > 1) $new[] = $in[$key] ."-". Implode("-",Array_slice($in,$key+2)); // $key and last item, except if iteration has come to far if($count-1 - $key >1) $new[] = $in[$key] ."-". $in[$count-1]; } $new = array_unique($new); // remove any duplicates that may have been created $result = array( 0 => 'e1', 1 => 'e1-e2', 2 => 'e1-e2-e3', 3 => 'e1-e2-e3-e4', 4 => 'e1-e2-e4', 5 => 'e1-e3', 6 => 'e1-e3-e4', 7 => 'e1-e4', 8 => 'e2', 9 => 'e2-e3', 10 => 'e2-e3-e4', 11 => 'e2-e4', 12 => 'e3', 13 => 'e3-e4', 14 => 'e4' ); var_dump(array_diff($new,$result)); // compare arrays if there is any difference Var_dump($new, $result); // output them
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 91
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 91
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 33
Branch analysis from position: 33
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 10
Branch analysis from position: 36
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 53
Branch analysis from position: 40
2 jumps found. (Code = 43) Position 1 = 57, Position 2 = 64
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 68, Position 2 = 79
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 83, Position 2 = 90
Branch analysis from position: 83
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 90
Branch analysis from position: 79
Branch analysis from position: 64
Branch analysis from position: 53
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 21
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 10
Branch analysis from position: 36
Branch analysis from position: 10
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 32
Branch analysis from position: 24
2 jumps found. (Code = 44) Position 1 = 36, Position 2 = 10
Branch analysis from position: 36
Branch analysis from position: 10
Branch analysis from position: 32
Branch analysis from position: 91
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 91
filename:       /in/uEfh6
function name:  (null)
number of ops:  109
compiled vars:  !0 = $in, !1 = $count, !2 = $val, !3 = $key, !4 = $new, !5 = $i, !6 = $result
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
    6     1        COUNT                                                ~8      !0
          2        ASSIGN                                                       !1, ~8
    7     3      > FE_RESET_R                                           $10     !0, ->91
          4    > > FE_FETCH_R                                           ~11     $10, !2, ->91
          5    >   ASSIGN                                                       !3, ~11
    8     6        ASSIGN_DIM                                                   !4
          7        OP_DATA                                                      !2
   11     8        ASSIGN                                                       !5, !3
          9      > JMP                                                          ->33
   12    10    >   IS_NOT_EQUAL                                                 !3, 0
         11      > JMPZ                                                         ~15, ->21
   13    12    >   INIT_FCALL                                                   'array_slice'
         13        SEND_VAR                                                     !0
         14        SEND_VAR                                                     !3
         15        SEND_VAR                                                     !5
         16        DO_ICALL                                             $17     
         17        FRAMELESS_ICALL_2                implode             ~18     '-', $17
         18        ASSIGN_DIM                                                   !4
         19        OP_DATA                                                      ~18
   12    20      > JMP                                                          ->32
   15    21    >   SUB                                                  ~19     !5, !3
         22        IS_SMALLER                                                   1, ~19
         23      > JMPZ                                                         ~20, ->32
         24    >   INIT_FCALL                                                   'array_slice'
         25        SEND_VAR                                                     !0
         26        SEND_VAR                                                     !3
         27        SEND_VAR                                                     !5
         28        DO_ICALL                                             $22     
         29        FRAMELESS_ICALL_2                implode             ~23     '-', $22
         30        ASSIGN_DIM                                                   !4
         31        OP_DATA                                                      ~23
   11    32    >   PRE_INC                                                      !5
         33    >   SUB                                                  ~25     !1, !3
         34        IS_SMALLER_OR_EQUAL                                          !5, ~25
         35      > JMPNZ                                                        ~26, ->10
   20    36    >   SUB                                                  ~27     !1, 2
         37        SUB                                                  ~28     ~27, !3
         38        IS_SMALLER                                                   1, ~28
         39      > JMPZ                                                         ~29, ->53
         40    >   INIT_FCALL                                                   'array_slice'
         41        SEND_VAR                                                     !0
         42        SEND_VAR                                                     !3
         43        SUB                                                  ~31     !1, 2
         44        SEND_VAL                                                     ~31
         45        DO_ICALL                                             $32     
         46        FRAMELESS_ICALL_2                implode             ~33     '-', $32
         47        CONCAT                                               ~34     ~33, '-'
         48        SUB                                                  ~35     !1, 1
         49        FETCH_DIM_R                                          ~36     !0, ~35
         50        CONCAT                                               ~37     ~34, ~36
         51        ASSIGN_DIM                                                   !4
         52        OP_DATA                                                      ~37
   23    53    >   SUB                                                  ~38     !1, 2
         54        SUB                                                  ~39     ~38, !3
         55        IS_SMALLER                                                   1, ~39
         56      > JMPZ                                                         ~40, ->64
         57    >   FETCH_DIM_R                                          ~42     !0, !3
         58        CONCAT                                               ~43     ~42, '-'
         59        ADD                                                  ~44     !3, 2
         60        FETCH_DIM_R                                          ~45     !0, ~44
         61        CONCAT                                               ~46     ~43, ~45
         62        ASSIGN_DIM                                                   !4
         63        OP_DATA                                                      ~46
   26    64    >   SUB                                                  ~47     !1, 2
         65        SUB                                                  ~48     ~47, !3
         66        IS_SMALLER                                                   1, ~48
         67      > JMPZ                                                         ~49, ->79
         68    >   FETCH_DIM_R                                          ~51     !0, !3
         69        CONCAT                                               ~52     ~51, '-'
         70        INIT_FCALL                                                   'array_slice'
         71        SEND_VAR                                                     !0
         72        ADD                                                  ~53     !3, 2
         73        SEND_VAL                                                     ~53
         74        DO_ICALL                                             $54     
         75        FRAMELESS_ICALL_2                implode             ~55     '-', $54
         76        CONCAT                                               ~56     ~52, ~55
         77        ASSIGN_DIM                                                   !4
         78        OP_DATA                                                      ~56
   29    79    >   SUB                                                  ~57     !1, 1
         80        SUB                                                  ~58     ~57, !3
         81        IS_SMALLER                                                   1, ~58
         82      > JMPZ                                                         ~59, ->90
         83    >   FETCH_DIM_R                                          ~61     !0, !3
         84        CONCAT                                               ~62     ~61, '-'
         85        SUB                                                  ~63     !1, 1
         86        FETCH_DIM_R                                          ~64     !0, ~63
         87        CONCAT                                               ~65     ~62, ~64
         88        ASSIGN_DIM                                                   !4
         89        OP_DATA                                                      ~65
    7    90    > > JMP                                                          ->4
         91    >   FE_FREE                                                      $10
   34    92        INIT_FCALL                                                   'array_unique'
         93        SEND_VAR                                                     !4
         94        DO_ICALL                                             $66     
         95        ASSIGN                                                       !4, $66
   35    96        ASSIGN                                                       !6, <array>
   52    97        INIT_FCALL                                                   'var_dump'
         98        INIT_FCALL                                                   'array_diff'
         99        SEND_VAR                                                     !4
        100        SEND_VAR                                                     !6
        101        DO_ICALL                                             $69     
        102        SEND_VAR                                                     $69
        103        DO_ICALL                                                     
   53   104        INIT_FCALL                                                   'var_dump'
        105        SEND_VAR                                                     !4
        106        SEND_VAR                                                     !6
        107        DO_ICALL                                                     
        108      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
159.01 ms | 2213 KiB | 17 Q