3v4l.org

run code in 500+ PHP versions simultaneously
<?php $arr1 = array( 0 => ['product_type'=>'manufacturer','id'=>1], 1 => ['product_type'=>'manufacturer','id'=>2], 2 => ['product_type'=>'seller'], 3 => ['product_type'=>'seller'], 4 => ['product_type'=>'seller'], 5 => ['product_type'=>'seller'], 6 => ['product_type'=>'seller'], 7 => ['product_type'=>'manufacturer','id'=>3], ) ; function rearrange(&$arr, $n) { for ($i = 0; $i < $n; $i++) { $j = $i+1; if($arr[$i]['product_type'] =='manufacturer'){ if($j%4!= 0){ //echo $i; $temp = $arr[$i]; $arr[$i] = $arr[$i + 1]; $arr[$i + 1] = $temp; } else { if ($i==0 || $i==1 || $i==2) { $temp = $arr[$i]; $arr[$i] = $arr[$i + 1]; $arr[$i + 1] = $temp; } else { $temp = $arr[$i]; $arr[$i] = $temp; } } } else { $temp = $arr[$i]; $arr[$i] = $temp; } } return $arr; } $keys = array_keys ($arr1); $n = count ($keys); $arr = rearrange($arr1, $n); print_r($arr);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WXd8E
function name:  (null)
number of ops:  16
compiled vars:  !0 = $arr1, !1 = $keys, !2 = $n, !3 = $arr
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                       !0, <array>
   46     1        INIT_FCALL                                                   'array_keys'
          2        SEND_VAR                                                     !0
          3        DO_ICALL                                             $5      
          4        ASSIGN                                                       !1, $5
   47     5        COUNT                                                ~7      !1
          6        ASSIGN                                                       !2, ~7
   48     7        INIT_FCALL                                                   'rearrange'
          8        SEND_REF                                                     !0
          9        SEND_VAR                                                     !2
         10        DO_FCALL                                          0  $9      
         11        ASSIGN                                                       !3, $9
   49    12        INIT_FCALL                                                   'print_r'
         13        SEND_VAR                                                     !3
         14        DO_ICALL                                                     
         15      > RETURN                                                       1

Function rearrange:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 51
Branch analysis from position: 51
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 4
Branch analysis from position: 53
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 46
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 13, Position 2 = 23
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 4
Branch analysis from position: 53
Branch analysis from position: 4
Branch analysis from position: 23
2 jumps found. (Code = 47) Position 1 = 25, Position 2 = 27
Branch analysis from position: 25
2 jumps found. (Code = 47) Position 1 = 28, Position 2 = 30
Branch analysis from position: 28
2 jumps found. (Code = 43) Position 1 = 31, Position 2 = 41
Branch analysis from position: 31
1 jumps found. (Code = 42) Position 1 = 45
Branch analysis from position: 45
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 50
Branch analysis from position: 50
Branch analysis from position: 30
Branch analysis from position: 27
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 53, Position 2 = 4
Branch analysis from position: 53
Branch analysis from position: 4
filename:       /in/WXd8E
function name:  rearrange
number of ops:  55
compiled vars:  !0 = $arr, !1 = $n, !2 = $i, !3 = $j, !4 = $temp
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   17     2        ASSIGN                                                       !2, 0
          3      > JMP                                                          ->51
   19     4    >   ADD                                                  ~6      !2, 1
          5        ASSIGN                                                       !3, ~6
   20     6        FETCH_DIM_R                                          ~8      !0, !2
          7        FETCH_DIM_R                                          ~9      ~8, 'product_type'
          8        IS_EQUAL                                                     ~9, 'manufacturer'
          9      > JMPZ                                                         ~10, ->46
   21    10    >   MOD                                                  ~11     !3, 4
         11        IS_NOT_EQUAL                                                 ~11, 0
         12      > JMPZ                                                         ~12, ->23
   23    13    >   FETCH_DIM_R                                          ~13     !0, !2
         14        ASSIGN                                                       !4, ~13
   24    15        ADD                                                  ~16     !2, 1
         16        FETCH_DIM_R                                          ~17     !0, ~16
         17        ASSIGN_DIM                                                   !0, !2
         18        OP_DATA                                                      ~17
   25    19        ADD                                                  ~18     !2, 1
         20        ASSIGN_DIM                                                   !0, ~18
         21        OP_DATA                                                      !4
   21    22      > JMP                                                          ->45
   27    23    >   IS_EQUAL                                             ~20     !2, 0
         24      > JMPNZ_EX                                             ~20     ~20, ->27
         25    >   IS_EQUAL                                             ~21     !2, 1
         26        BOOL                                                 ~20     ~21
         27    > > JMPNZ_EX                                             ~20     ~20, ->30
         28    >   IS_EQUAL                                             ~22     !2, 2
         29        BOOL                                                 ~20     ~22
         30    > > JMPZ                                                         ~20, ->41
   28    31    >   FETCH_DIM_R                                          ~23     !0, !2
         32        ASSIGN                                                       !4, ~23
   29    33        ADD                                                  ~26     !2, 1
         34        FETCH_DIM_R                                          ~27     !0, ~26
         35        ASSIGN_DIM                                                   !0, !2
         36        OP_DATA                                                      ~27
   30    37        ADD                                                  ~28     !2, 1
         38        ASSIGN_DIM                                                   !0, ~28
         39        OP_DATA                                                      !4
   27    40      > JMP                                                          ->45
   32    41    >   FETCH_DIM_R                                          ~30     !0, !2
         42        ASSIGN                                                       !4, ~30
   33    43        ASSIGN_DIM                                                   !0, !2
         44        OP_DATA                                                      !4
   20    45    > > JMP                                                          ->50
   38    46    >   FETCH_DIM_R                                          ~33     !0, !2
         47        ASSIGN                                                       !4, ~33
   39    48        ASSIGN_DIM                                                   !0, !2
         49        OP_DATA                                                      !4
   17    50    >   PRE_INC                                                      !2
         51    >   IS_SMALLER                                                   !2, !1
         52      > JMPNZ                                                        ~37, ->4
   44    53    > > RETURN                                                       !0
   45    54*     > RETURN                                                       null

End of function rearrange

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
227.02 ms | 2188 KiB | 16 Q