3v4l.org

run code in 300+ 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 = 103
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 103
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 39
Branch analysis from position: 39
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 10
Branch analysis from position: 42
2 jumps found. (Code = 43) Position 1 = 46, Position 2 = 62
Branch analysis from position: 46
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 73
Branch analysis from position: 66
2 jumps found. (Code = 43) Position 1 = 77, Position 2 = 91
Branch analysis from position: 77
2 jumps found. (Code = 43) Position 1 = 95, Position 2 = 102
Branch analysis from position: 95
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 102
Branch analysis from position: 91
Branch analysis from position: 73
Branch analysis from position: 62
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 24
Branch analysis from position: 12
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 10
Branch analysis from position: 42
Branch analysis from position: 10
Branch analysis from position: 24
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 38
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 42, Position 2 = 10
Branch analysis from position: 42
Branch analysis from position: 10
Branch analysis from position: 38
Branch analysis from position: 103
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 103
filename:       /in/uEfh6
function name:  (null)
number of ops:  121
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, ->103
          4    > > FE_FETCH_R                                       ~11     $10, !2, ->103
          5    >   ASSIGN                                                   !3, ~11
    8     6        ASSIGN_DIM                                               !4
          7        OP_DATA                                                  !2
   11     8        ASSIGN                                                   !5, !3
          9      > JMP                                                      ->39
   12    10    >   IS_NOT_EQUAL                                             !3, 0
         11      > JMPZ                                                     ~15, ->24
   13    12    >   INIT_FCALL                                               'implode'
         13        SEND_VAL                                                 '-'
         14        INIT_FCALL                                               'array_slice'
         15        SEND_VAR                                                 !0
         16        SEND_VAR                                                 !3
         17        SEND_VAR                                                 !5
         18        DO_ICALL                                         $17     
         19        SEND_VAR                                                 $17
         20        DO_ICALL                                         $18     
         21        ASSIGN_DIM                                               !4
         22        OP_DATA                                                  $18
         23      > JMP                                                      ->38
   15    24    >   SUB                                              ~19     !5, !3
         25        IS_SMALLER                                               1, ~19
         26      > JMPZ                                                     ~20, ->38
         27    >   INIT_FCALL                                               'implode'
         28        SEND_VAL                                                 '-'
         29        INIT_FCALL                                               'array_slice'
         30        SEND_VAR                                                 !0
         31        SEND_VAR                                                 !3
         32        SEND_VAR                                                 !5
         33        DO_ICALL                                         $22     
         34        SEND_VAR                                                 $22
         35        DO_ICALL                                         $23     
         36        ASSIGN_DIM                                               !4
         37        OP_DATA                                                  $23
   11    38    >   PRE_INC                                                  !5
         39    >   SUB                                              ~25     !1, !3
         40        IS_SMALLER_OR_EQUAL                                      !5, ~25
         41      > JMPNZ                                                    ~26, ->10
   20    42    >   SUB                                              ~27     !1, 2
         43        SUB                                              ~28     ~27, !3
         44        IS_SMALLER                                               1, ~28
         45      > JMPZ                                                     ~29, ->62
         46    >   INIT_FCALL                                               'implode'
         47        SEND_VAL                                                 '-'
         48        INIT_FCALL                                               'array_slice'
         49        SEND_VAR                                                 !0
         50        SEND_VAR                                                 !3
         51        SUB                                              ~31     !1, 2
         52        SEND_VAL                                                 ~31
         53        DO_ICALL                                         $32     
         54        SEND_VAR                                                 $32
         55        DO_ICALL                                         $33     
         56        CONCAT                                           ~34     $33, '-'
         57        SUB                                              ~35     !1, 1
         58        FETCH_DIM_R                                      ~36     !0, ~35
         59        CONCAT                                           ~37     ~34, ~36
         60        ASSIGN_DIM                                               !4
         61        OP_DATA                                                  ~37
   23    62    >   SUB                                              ~38     !1, 2
         63        SUB                                              ~39     ~38, !3
         64        IS_SMALLER                                               1, ~39
         65      > JMPZ                                                     ~40, ->73
         66    >   FETCH_DIM_R                                      ~42     !0, !3
         67        CONCAT                                           ~43     ~42, '-'
         68        ADD                                              ~44     !3, 2
         69        FETCH_DIM_R                                      ~45     !0, ~44
         70        CONCAT                                           ~46     ~43, ~45
         71        ASSIGN_DIM                                               !4
         72        OP_DATA                                                  ~46
   26    73    >   SUB                                              ~47     !1, 2
         74        SUB                                              ~48     ~47, !3
         75        IS_SMALLER                                               1, ~48
         76      > JMPZ                                                     ~49, ->91
         77    >   FETCH_DIM_R                                      ~51     !0, !3
         78        CONCAT                                           ~52     ~51, '-'
         79        INIT_FCALL                                               'implode'
         80        SEND_VAL                                                 '-'
         81        INIT_FCALL                                               'array_slice'
         82        SEND_VAR                                                 !0
         83        ADD                                              ~53     !3, 2
         84        SEND_VAL                                                 ~53
         85        DO_ICALL                                         $54     
         86        SEND_VAR                                                 $54
         87        DO_ICALL                                         $55     
         88        CONCAT                                           ~56     ~52, $55
         89        ASSIGN_DIM                                               !4
         90        OP_DATA                                                  ~56
   29    91    >   SUB                                              ~57     !1, 1
         92        SUB                                              ~58     ~57, !3
         93        IS_SMALLER                                               1, ~58
         94      > JMPZ                                                     ~59, ->102
         95    >   FETCH_DIM_R                                      ~61     !0, !3
         96        CONCAT                                           ~62     ~61, '-'
         97        SUB                                              ~63     !1, 1
         98        FETCH_DIM_R                                      ~64     !0, ~63
         99        CONCAT                                           ~65     ~62, ~64
        100        ASSIGN_DIM                                               !4
        101        OP_DATA                                                  ~65
    7   102    > > JMP                                                      ->4
        103    >   FE_FREE                                                  $10
   34   104        INIT_FCALL                                               'array_unique'
        105        SEND_VAR                                                 !4
        106        DO_ICALL                                         $66     
        107        ASSIGN                                                   !4, $66
   35   108        ASSIGN                                                   !6, <array>
   52   109        INIT_FCALL                                               'var_dump'
        110        INIT_FCALL                                               'array_diff'
        111        SEND_VAR                                                 !4
        112        SEND_VAR                                                 !6
        113        DO_ICALL                                         $69     
        114        SEND_VAR                                                 $69
        115        DO_ICALL                                                 
   53   116        INIT_FCALL                                               'var_dump'
        117        SEND_VAR                                                 !4
        118        SEND_VAR                                                 !6
        119        DO_ICALL                                                 
        120      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.07 ms | 1409 KiB | 23 Q