3v4l.org

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

End of function reorder

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
167.45 ms | 1407 KiB | 16 Q