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 = index - $newOrder; foreach ($orders as $i => $v) { if ($i < $index) { $lowers[] = $i; } if ($i > $index) { $uppers[] = $i; } } 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/1oZ8s
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
   43     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 = 14, Position 2 = 25
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 25
Branch analysis from position: 15
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
2 jumps found. (Code = 43) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 24
Branch analysis from position: 20
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 28, Position 2 = 46
Branch analysis from position: 28
2 jumps found. (Code = 77) Position 1 = 29, Position 2 = 36
Branch analysis from position: 29
2 jumps found. (Code = 78) Position 1 = 30, Position 2 = 36
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 29
Branch analysis from position: 29
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 38, Position 2 = 44
Branch analysis from position: 38
2 jumps found. (Code = 78) Position 1 = 39, Position 2 = 44
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 38
Branch analysis from position: 38
Branch analysis from position: 44
1 jumps found. (Code = 42) Position 1 = 63
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 44
Branch analysis from position: 36
Branch analysis from position: 46
2 jumps found. (Code = 77) Position 1 = 47, Position 2 = 54
Branch analysis from position: 47
2 jumps found. (Code = 78) Position 1 = 48, Position 2 = 54
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 47
Branch analysis from position: 47
Branch analysis from position: 54
2 jumps found. (Code = 77) Position 1 = 56, Position 2 = 62
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 62
Branch analysis from position: 57
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 62
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
Branch analysis from position: 54
Branch analysis from position: 25
filename:       /in/1oZ8s
function name:  reorder
number of ops:  67
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        FETCH_CONSTANT                                   ~16     'index'
         11        SUB                                              ~17     ~16, !1
         12        ASSIGN                                                   !7, ~17
   14    13      > FE_RESET_R                                       $19     !2, ->25
         14    > > FE_FETCH_R                                       ~20     $19, !8, ->25
         15    >   ASSIGN                                                   !9, ~20
   15    16        IS_SMALLER                                               !9, !0
         17      > JMPZ                                                     ~22, ->20
   16    18    >   ASSIGN_DIM                                               !5
         19        OP_DATA                                                  !9
   19    20    >   IS_SMALLER                                               !0, !9
         21      > JMPZ                                                     ~24, ->24
   20    22    >   ASSIGN_DIM                                               !6
         23        OP_DATA                                                  !9
   14    24    > > JMP                                                      ->14
         25    >   FE_FREE                                                  $19
   23    26        IS_SMALLER                                               !7, 0
         27      > JMPZ                                                     ~26, ->46
   24    28    > > FE_RESET_R                                       $27     !5, ->36
         29    > > FE_FETCH_R                                       ~28     $27, !8, ->36
         30    >   ASSIGN                                                   !9, ~28
   25    31        FETCH_DIM_R                                      ~31     !2, !8
         32        ADD                                              ~32     ~31, 1
         33        ASSIGN_DIM                                               !3, !8
         34        OP_DATA                                                  ~32
   24    35      > JMP                                                      ->29
         36    >   FE_FREE                                                  $27
   27    37      > FE_RESET_R                                       $33     !6, ->44
         38    > > FE_FETCH_R                                       ~34     $33, !8, ->44
         39    >   ASSIGN                                                   !9, ~34
   28    40        FETCH_DIM_R                                      ~37     !2, !8
         41        ASSIGN_DIM                                               !3, !8
         42        OP_DATA                                                  ~37
   27    43      > JMP                                                      ->38
         44    >   FE_FREE                                                  $33
         45      > JMP                                                      ->63
   31    46    > > FE_RESET_R                                       $38     !6, ->54
         47    > > FE_FETCH_R                                       ~39     $38, !8, ->54
         48    >   ASSIGN                                                   !9, ~39
   32    49        FETCH_DIM_R                                      ~42     !2, !8
         50        SUB                                              ~43     ~42, 1
         51        ASSIGN_DIM                                               !3, !8
         52        OP_DATA                                                  ~43
   31    53      > JMP                                                      ->47
         54    >   FE_FREE                                                  $38
   34    55      > FE_RESET_R                                       $44     !5, ->62
         56    > > FE_FETCH_R                                       ~45     $44, !8, ->62
         57    >   ASSIGN                                                   !9, ~45
   35    58        FETCH_DIM_R                                      ~48     !2, !8
         59        ASSIGN_DIM                                               !3, !8
         60        OP_DATA                                                  ~48
   34    61      > JMP                                                      ->56
         62    >   FE_FREE                                                  $44
   39    63    >   INIT_FCALL                                               'var_dump'
         64        SEND_VAR                                                 !3
         65        DO_ICALL                                                 
   41    66      > RETURN                                                   null

End of function reorder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
165.62 ms | 1407 KiB | 16 Q