3v4l.org

run code in 300+ PHP versions simultaneously
<?php $orders = array(1,2,3,4,5); $index = 2; $newOrder = 1; // 3,1,2,4,5 function reorder($index, $newOrder, $orders) { $newOrders = array(); $newOrders[$index] = $newOrder; $oldOrder = $orders[$index]; $lowers = array(); $uppers = array(); $direction = 0; foreach ($orders as $i => $v) { if ($i < $index) { $lowers[] = $i; } if ($i > $index) { $uppers[] = $i; } if ($i === $index) { $direction = $i - $newOrder; } } if ($direction > 0) { foreach ($lowers as $i => $v) { $newOrders[$v] = $orders[$v] + 1; } foreach ($uppers as $i => $v) { $newOrders[$v] = $orders[$v]; } } else { foreach ($uppers as $i => $v) { $newOrders[$v] = $orders[$v] - 1; } foreach ($lowers as $i => $v) { $newOrders[$v] = $orders[$v]; } } //ksort($newOrders); var_dump($newOrders); } reorder($index, $newOrder, $orders);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/AlFvs
function name:  (null)
number of ops:  9
compiled vars:  !0 = $orders, !1 = $index, !2 = $newOrder
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    4     1        ASSIGN                                                   !1, 2
    5     2        ASSIGN                                                   !2, 1
   47     3        INIT_FCALL                                               'reorder'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !2
          6        SEND_VAR                                                 !0
          7        DO_FCALL                                      0          
          8      > RETURN                                                   1

Function reorder:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 12, Position 2 = 27
Branch analysis from position: 12
2 jumps found. (Code = 78) Position 1 = 13, Position 2 = 27
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 22
Branch analysis from position: 20
2 jumps found. (Code = 43) Position 1 = 24, Position 2 = 26
Branch analysis from position: 24
1 jumps found. (Code = 42) Position 1 = 12
Branch analysis from position: 12
Branch analysis from position: 26
Branch analysis from position: 22
Branch analysis from position: 18
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 30, Position 2 = 48
Branch analysis from position: 30
2 jumps found. (Code = 77) Position 1 = 31, Position 2 = 38
Branch analysis from position: 31
2 jumps found. (Code = 78) Position 1 = 32, Position 2 = 38
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
Branch analysis from position: 38
2 jumps found. (Code = 77) Position 1 = 40, Position 2 = 46
Branch analysis from position: 40
2 jumps found. (Code = 78) Position 1 = 41, Position 2 = 46
Branch analysis from position: 41
1 jumps found. (Code = 42) Position 1 = 40
Branch analysis from position: 40
Branch analysis from position: 46
1 jumps found. (Code = 42) Position 1 = 65
Branch analysis from position: 65
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
Branch analysis from position: 38
Branch analysis from position: 48
2 jumps found. (Code = 77) Position 1 = 49, Position 2 = 56
Branch analysis from position: 49
2 jumps found. (Code = 78) Position 1 = 50, Position 2 = 56
Branch analysis from position: 50
1 jumps found. (Code = 42) Position 1 = 49
Branch analysis from position: 49
Branch analysis from position: 56
2 jumps found. (Code = 77) Position 1 = 58, Position 2 = 64
Branch analysis from position: 58
2 jumps found. (Code = 78) Position 1 = 59, Position 2 = 64
Branch analysis from position: 59
1 jumps found. (Code = 42) Position 1 = 58
Branch analysis from position: 58
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 56
Branch analysis from position: 27
filename:       /in/AlFvs
function name:  reorder
number of ops:  69
compiled vars:  !0 = $index, !1 = $newOrder, !2 = $orders, !3 = $newOrders, !4 = $oldOrder, !5 = $lowers, !6 = $uppers, !7 = $direction, !8 = $v, !9 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
    7     3        ASSIGN                                                   !3, <array>
    8     4        ASSIGN_DIM                                               !3, !0
          5        OP_DATA                                                  !1
    9     6        FETCH_DIM_R                                      ~12     !2, !0
          7        ASSIGN                                                   !4, ~12
   10     8        ASSIGN                                                   !5, <array>
   11     9        ASSIGN                                                   !6, <array>
   12    10        ASSIGN                                                   !7, 0
   14    11      > FE_RESET_R                                       $17     !2, ->27
         12    > > FE_FETCH_R                                       ~18     $17, !8, ->27
         13    >   ASSIGN                                                   !9, ~18
   15    14        IS_SMALLER                                               !9, !0
         15      > JMPZ                                                     ~20, ->18
   16    16    >   ASSIGN_DIM                                               !5
         17        OP_DATA                                                  !9
   19    18    >   IS_SMALLER                                               !0, !9
         19      > JMPZ                                                     ~22, ->22
   20    20    >   ASSIGN_DIM                                               !6
         21        OP_DATA                                                  !9
   23    22    >   IS_IDENTICAL                                             !9, !0
         23      > JMPZ                                                     ~24, ->26
   24    24    >   SUB                                              ~25     !9, !1
         25        ASSIGN                                                   !7, ~25
   14    26    > > JMP                                                      ->12
         27    >   FE_FREE                                                  $17
   27    28        IS_SMALLER                                               0, !7
         29      > JMPZ                                                     ~27, ->48
   28    30    > > FE_RESET_R                                       $28     !5, ->38
         31    > > FE_FETCH_R                                       ~29     $28, !8, ->38
         32    >   ASSIGN                                                   !9, ~29
   29    33        FETCH_DIM_R                                      ~32     !2, !8
         34        ADD                                              ~33     ~32, 1
         35        ASSIGN_DIM                                               !3, !8
         36        OP_DATA                                                  ~33
   28    37      > JMP                                                      ->31
         38    >   FE_FREE                                                  $28
   31    39      > FE_RESET_R                                       $34     !6, ->46
         40    > > FE_FETCH_R                                       ~35     $34, !8, ->46
         41    >   ASSIGN                                                   !9, ~35
   32    42        FETCH_DIM_R                                      ~38     !2, !8
         43        ASSIGN_DIM                                               !3, !8
         44        OP_DATA                                                  ~38
   31    45      > JMP                                                      ->40
         46    >   FE_FREE                                                  $34
         47      > JMP                                                      ->65
   35    48    > > FE_RESET_R                                       $39     !6, ->56
         49    > > FE_FETCH_R                                       ~40     $39, !8, ->56
         50    >   ASSIGN                                                   !9, ~40
   36    51        FETCH_DIM_R                                      ~43     !2, !8
         52        SUB                                              ~44     ~43, 1
         53        ASSIGN_DIM                                               !3, !8
         54        OP_DATA                                                  ~44
   35    55      > JMP                                                      ->49
         56    >   FE_FREE                                                  $39
   38    57      > FE_RESET_R                                       $45     !5, ->64
         58    > > FE_FETCH_R                                       ~46     $45, !8, ->64
         59    >   ASSIGN                                                   !9, ~46
   39    60        FETCH_DIM_R                                      ~49     !2, !8
         61        ASSIGN_DIM                                               !3, !8
         62        OP_DATA                                                  ~49
   38    63      > JMP                                                      ->58
         64    >   FE_FREE                                                  $45
   43    65    >   INIT_FCALL                                               'var_dump'
         66        SEND_VAR                                                 !3
         67        DO_ICALL                                                 
   45    68      > RETURN                                                   null

End of function reorder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
159.19 ms | 1407 KiB | 16 Q