3v4l.org

run code in 300+ PHP versions simultaneously
<?php $old_arr=array(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20); $size = count($old_arr); print_r($size); for($i=0;$i<=19;$i++){ if ($i<=4){ $a[] = $old_arr[$i]; }elseif ($i>4 && $i<=9){ $b[] = $old_arr[$i]; }elseif ($i>9 && $i<=14){ $c[] = $old_arr[$i]; }elseif ($i>14){ $d[] = $old_arr[$i]; } } print_r($a); print_r($b); print_r($c); print_r($d); $new_arr = array(); $group_order[] = array(); $temp = 0; while(count($new_arr)<$size){ if (!empty($group_order)){ $temp = $group_order[3]; } foreach ($group_order as $i => $value) { unset($group_order[$i]); } $group_order = array_values($group_order); while(count($group_order)<4){ $x=mt_rand(1,4); if(in_array($x,$group_order) == false && $x != $temp){ $group_order[] = $x; $temp = 0; } } foreach ($group_order as $value){ if ($value == 1){ $idx = mt_rand(0,(count($a)-1)); $new_arr[] = $a[$idx]; unset($a[$idx]); $a = array_values($a); }elseif ($value == 2){ $idx = mt_rand(0,(count($b)-1)); $new_arr[] = $b[$idx]; unset($b[$idx]); $b = array_values($b); }elseif ($value == 3){ $idx = mt_rand(0,(count($c)-1)); $new_arr[] = $c[$idx]; unset($c[$idx]); $c = array_values($c); }elseif ($value == 4){ $idx = mt_rand(0,(count($d)-1)); $new_arr[] = $d[$idx]; unset($d[$idx]); $d = array_values($d); } } } print_r($new_arr); ?>
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 8
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 168
Branch analysis from position: 168
2 jumps found. (Code = 44) Position 1 = 171, Position 2 = 57
Branch analysis from position: 171
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
2 jumps found. (Code = 77) Position 1 = 63, Position 2 = 67
Branch analysis from position: 63
2 jumps found. (Code = 78) Position 1 = 64, Position 2 = 67
Branch analysis from position: 64
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
Branch analysis from position: 67
1 jumps found. (Code = 42) Position 1 = 90
Branch analysis from position: 90
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 73
Branch analysis from position: 93
2 jumps found. (Code = 77) Position 1 = 94, Position 2 = 167
Branch analysis from position: 94
2 jumps found. (Code = 78) Position 1 = 95, Position 2 = 167
Branch analysis from position: 95
2 jumps found. (Code = 43) Position 1 = 97, Position 2 = 113
Branch analysis from position: 97
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 113
2 jumps found. (Code = 43) Position 1 = 115, Position 2 = 131
Branch analysis from position: 115
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
Branch analysis from position: 131
2 jumps found. (Code = 43) Position 1 = 133, Position 2 = 149
Branch analysis from position: 133
1 jumps found. (Code = 42) Position 1 = 166
Branch analysis from position: 166
Branch analysis from position: 149
2 jumps found. (Code = 43) Position 1 = 151, Position 2 = 166
Branch analysis from position: 151
1 jumps found. (Code = 42) Position 1 = 94
Branch analysis from position: 94
Branch analysis from position: 166
Branch analysis from position: 167
2 jumps found. (Code = 44) Position 1 = 171, Position 2 = 57
Branch analysis from position: 171
Branch analysis from position: 57
Branch analysis from position: 167
Branch analysis from position: 73
2 jumps found. (Code = 46) Position 1 = 84, Position 2 = 86
Branch analysis from position: 84
2 jumps found. (Code = 43) Position 1 = 87, Position 2 = 90
Branch analysis from position: 87
2 jumps found. (Code = 44) Position 1 = 93, Position 2 = 73
Branch analysis from position: 93
Branch analysis from position: 73
Branch analysis from position: 90
Branch analysis from position: 86
Branch analysis from position: 67
Branch analysis from position: 62
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 14
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 8
Branch analysis from position: 40
Branch analysis from position: 8
Branch analysis from position: 14
2 jumps found. (Code = 46) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 23
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 23
2 jumps found. (Code = 46) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 32
Branch analysis from position: 28
1 jumps found. (Code = 42) Position 1 = 37
Branch analysis from position: 37
Branch analysis from position: 32
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
2 jumps found. (Code = 44) Position 1 = 40, Position 2 = 8
Branch analysis from position: 40
Branch analysis from position: 8
Branch analysis from position: 37
Branch analysis from position: 27
Branch analysis from position: 18
filename:       /in/MhGWo
function name:  (null)
number of ops:  175
compiled vars:  !0 = $old_arr, !1 = $size, !2 = $i, !3 = $a, !4 = $b, !5 = $c, !6 = $d, !7 = $new_arr, !8 = $group_order, !9 = $temp, !10 = $value, !11 = $x, !12 = $idx
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    4     1        COUNT                                            ~14     !0
          2        ASSIGN                                                   !1, ~14
    5     3        INIT_FCALL                                               'print_r'
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                                 
    7     6        ASSIGN                                                   !2, 0
          7      > JMP                                                      ->38
    8     8    >   IS_SMALLER_OR_EQUAL                                      !2, 4
          9      > JMPZ                                                     ~18, ->14
    9    10    >   FETCH_DIM_R                                      ~20     !0, !2
         11        ASSIGN_DIM                                               !3
         12        OP_DATA                                                  ~20
         13      > JMP                                                      ->37
   10    14    >   IS_SMALLER                                       ~21     4, !2
         15      > JMPZ_EX                                          ~21     ~21, ->18
         16    >   IS_SMALLER_OR_EQUAL                              ~22     !2, 9
         17        BOOL                                             ~21     ~22
         18    > > JMPZ                                                     ~21, ->23
   11    19    >   FETCH_DIM_R                                      ~24     !0, !2
         20        ASSIGN_DIM                                               !4
         21        OP_DATA                                                  ~24
         22      > JMP                                                      ->37
   12    23    >   IS_SMALLER                                       ~25     9, !2
         24      > JMPZ_EX                                          ~25     ~25, ->27
         25    >   IS_SMALLER_OR_EQUAL                              ~26     !2, 14
         26        BOOL                                             ~25     ~26
         27    > > JMPZ                                                     ~25, ->32
   13    28    >   FETCH_DIM_R                                      ~28     !0, !2
         29        ASSIGN_DIM                                               !5
         30        OP_DATA                                                  ~28
         31      > JMP                                                      ->37
   14    32    >   IS_SMALLER                                               14, !2
         33      > JMPZ                                                     ~29, ->37
   15    34    >   FETCH_DIM_R                                      ~31     !0, !2
         35        ASSIGN_DIM                                               !6
         36        OP_DATA                                                  ~31
    7    37    >   PRE_INC                                                  !2
         38    >   IS_SMALLER_OR_EQUAL                                      !2, 19
         39      > JMPNZ                                                    ~33, ->8
   18    40    >   INIT_FCALL                                               'print_r'
         41        SEND_VAR                                                 !3
         42        DO_ICALL                                                 
   19    43        INIT_FCALL                                               'print_r'
         44        SEND_VAR                                                 !4
         45        DO_ICALL                                                 
   20    46        INIT_FCALL                                               'print_r'
         47        SEND_VAR                                                 !5
         48        DO_ICALL                                                 
   21    49        INIT_FCALL                                               'print_r'
         50        SEND_VAR                                                 !6
         51        DO_ICALL                                                 
   23    52        ASSIGN                                                   !7, <array>
   24    53        ASSIGN_DIM                                               !8
         54        OP_DATA                                                  <array>
   25    55        ASSIGN                                                   !9, 0
   26    56      > JMP                                                      ->168
   27    57    >   ISSET_ISEMPTY_CV                                 ~41     !8
         58        BOOL_NOT                                         ~42     ~41
         59      > JMPZ                                                     ~42, ->62
   28    60    >   FETCH_DIM_R                                      ~43     !8, 3
         61        ASSIGN                                                   !9, ~43
   30    62    > > FE_RESET_R                                       $45     !8, ->67
         63    > > FE_FETCH_R                                       ~46     $45, !10, ->67
         64    >   ASSIGN                                                   !2, ~46
   31    65        UNSET_DIM                                                !8, !2
   30    66      > JMP                                                      ->63
         67    >   FE_FREE                                                  $45
   33    68        INIT_FCALL                                               'array_values'
         69        SEND_VAR                                                 !8
         70        DO_ICALL                                         $48     
         71        ASSIGN                                                   !8, $48
   37    72      > JMP                                                      ->90
   38    73    >   INIT_FCALL                                               'mt_rand'
         74        SEND_VAL                                                 1
         75        SEND_VAL                                                 4
         76        DO_ICALL                                         $50     
         77        ASSIGN                                                   !11, $50
   39    78        INIT_FCALL                                               'in_array'
         79        SEND_VAR                                                 !11
         80        SEND_VAR                                                 !8
         81        DO_ICALL                                         $52     
         82        BOOL_NOT                                         ~53     $52
         83      > JMPZ_EX                                          ~53     ~53, ->86
         84    >   IS_NOT_EQUAL                                     ~54     !11, !9
         85        BOOL                                             ~53     ~54
         86    > > JMPZ                                                     ~53, ->90
   40    87    >   ASSIGN_DIM                                               !8
         88        OP_DATA                                                  !11
   41    89        ASSIGN                                                   !9, 0
   37    90    >   COUNT                                            ~57     !8
         91        IS_SMALLER                                               ~57, 4
         92      > JMPNZ                                                    ~58, ->73
   45    93    > > FE_RESET_R                                       $59     !8, ->167
         94    > > FE_FETCH_R                                               $59, !10, ->167
   46    95    >   IS_EQUAL                                                 !10, 1
         96      > JMPZ                                                     ~60, ->113
   47    97    >   INIT_FCALL                                               'mt_rand'
         98        SEND_VAL                                                 0
         99        COUNT                                            ~61     !3
        100        SUB                                              ~62     ~61, 1
        101        SEND_VAL                                                 ~62
        102        DO_ICALL                                         $63     
        103        ASSIGN                                                   !12, $63
   48   104        FETCH_DIM_R                                      ~66     !3, !12
        105        ASSIGN_DIM                                               !7
        106        OP_DATA                                                  ~66
   49   107        UNSET_DIM                                                !3, !12
   50   108        INIT_FCALL                                               'array_values'
        109        SEND_VAR                                                 !3
        110        DO_ICALL                                         $67     
        111        ASSIGN                                                   !3, $67
        112      > JMP                                                      ->166
   51   113    >   IS_EQUAL                                                 !10, 2
        114      > JMPZ                                                     ~69, ->131
   52   115    >   INIT_FCALL                                               'mt_rand'
        116        SEND_VAL                                                 0
        117        COUNT                                            ~70     !4
        118        SUB                                              ~71     ~70, 1
        119        SEND_VAL                                                 ~71
        120        DO_ICALL                                         $72     
        121        ASSIGN                                                   !12, $72
   53   122        FETCH_DIM_R                                      ~75     !4, !12
        123        ASSIGN_DIM                                               !7
        124        OP_DATA                                                  ~75
   54   125        UNSET_DIM                                                !4, !12
   55   126        INIT_FCALL                                               'array_values'
        127        SEND_VAR                                                 !4
        128        DO_ICALL                                         $76     
        129        ASSIGN                                                   !4, $76
        130      > JMP                                                      ->166
   56   131    >   IS_EQUAL                                                 !10, 3
        132      > JMPZ                                                     ~78, ->149
   57   133    >   INIT_FCALL                                               'mt_rand'
        134        SEND_VAL                                                 0
        135        COUNT                                            ~79     !5
        136        SUB                                              ~80     ~79, 1
        137        SEND_VAL                                                 ~80
        138        DO_ICALL                                         $81     
        139        ASSIGN                                                   !12, $81
   58   140        FETCH_DIM_R                                      ~84     !5, !12
        141        ASSIGN_DIM                                               !7
        142        OP_DATA                                                  ~84
   59   143        UNSET_DIM                                                !5, !12
   60   144        INIT_FCALL                                               'array_values'
        145        SEND_VAR                                                 !5
        146        DO_ICALL                                         $85     
        147        ASSIGN                                                   !5, $85
        148      > JMP                                                      ->166
   61   149    >   IS_EQUAL                                                 !10, 4
        150      > JMPZ                                                     ~87, ->166
   62   151    >   INIT_FCALL                                               'mt_rand'
        152        SEND_VAL                                                 0
        153        COUNT                                            ~88     !6
        154        SUB                                              ~89     ~88, 1
        155        SEND_VAL                                                 ~89
        156        DO_ICALL                                         $90     
        157        ASSIGN                                                   !12, $90
   63   158        FETCH_DIM_R                                      ~93     !6, !12
        159        ASSIGN_DIM                                               !7
        160        OP_DATA                                                  ~93
   64   161        UNSET_DIM                                                !6, !12
   65   162        INIT_FCALL                                               'array_values'
        163        SEND_VAR                                                 !6
        164        DO_ICALL                                         $94     
        165        ASSIGN                                                   !6, $94
   45   166    > > JMP                                                      ->94
        167    >   FE_FREE                                                  $59
   26   168    >   COUNT                                            ~96     !7
        169        IS_SMALLER                                               ~96, !1
        170      > JMPNZ                                                    ~97, ->57
   71   171    >   INIT_FCALL                                               'print_r'
        172        SEND_VAR                                                 !7
        173        DO_ICALL                                                 
   73   174      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
150.66 ms | 1412 KiB | 21 Q