3v4l.org

run code in 300+ PHP versions simultaneously
<?php /* Build the array */ $result = []; for($i=0;$i<4;$i++){ $result[] = [ 'id' => $i + 1, 'title' => 'task '.($i + 1), 'tech_user_id' => 1, 'dev_priority' => $i + 1 ]; } /* Build the array ends */ function reArrange(&$result,$id,$new_dev_priority){ $curr_index = array_search($id,array_column($result,"id"),true); $limit_index = array_search($new_dev_priority,array_column($result,"dev_priority"),true); $process_node = $result[$curr_index]; $curr_dev_priority = $process_node['dev_priority']; if($curr_dev_priority === $new_dev_priority) return; // return if same priority was assigned. $offset = $curr_dev_priority > $new_dev_priority ? -1 : 1; /* rearrange by relocating elements to a new location(this is a minimized push) */ while($curr_index != $limit_index){ $result[$curr_index] = $result[$curr_index + $offset]; $result[$curr_index]['dev_priority'] = $result[$curr_index]['dev_priority'] - $offset; $curr_index += $offset; } $process_node['dev_priority'] = $new_dev_priority; // assign new dev priority $result[$curr_index] = $process_node; } echo "Initial state:##########",PHP_EOL; print_r($result); reArrange($result,3,1); echo "Rearranged state:##########",PHP_EOL; print_r($result);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 3
2 jumps found. (Code = 44) Position 1 = 16, Position 2 = 3
Branch analysis from position: 16
Branch analysis from position: 3
filename:       /in/nggja
function name:  (null)
number of ops:  32
compiled vars:  !0 = $result, !1 = $i
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   ASSIGN                                                   !0, <array>
    6     1        ASSIGN                                                   !1, 0
          2      > JMP                                                      ->14
    8     3    >   ADD                                              ~5      !1, 1
          4        INIT_ARRAY                                       ~6      ~5, 'id'
    9     5        ADD                                              ~7      !1, 1
          6        CONCAT                                           ~8      'task+', ~7
          7        ADD_ARRAY_ELEMENT                                ~6      ~8, 'title'
   10     8        ADD_ARRAY_ELEMENT                                ~6      1, 'tech_user_id'
   11     9        ADD                                              ~9      !1, 1
         10        ADD_ARRAY_ELEMENT                                ~6      ~9, 'dev_priority'
    7    11        ASSIGN_DIM                                               !0
   11    12        OP_DATA                                                  ~6
    6    13        PRE_INC                                                  !1
         14    >   IS_SMALLER                                               !1, 4
         15      > JMPNZ                                                    ~11, ->3
   37    16    >   ECHO                                                     'Initial+state%3A%23%23%23%23%23%23%23%23%23%23'
         17        ECHO                                                     '%0A'
   39    18        INIT_FCALL                                               'print_r'
         19        SEND_VAR                                                 !0
         20        DO_ICALL                                                 
   40    21        INIT_FCALL                                               'rearrange'
         22        SEND_REF                                                 !0
         23        SEND_VAL                                                 3
         24        SEND_VAL                                                 1
         25        DO_FCALL                                      0          
   41    26        ECHO                                                     'Rearranged+state%3A%23%23%23%23%23%23%23%23%23%23'
         27        ECHO                                                     '%0A'
   42    28        INIT_FCALL                                               'print_r'
         29        SEND_VAR                                                 !0
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Function rearrange:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 29, Position 2 = 30
Branch analysis from position: 29
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 30
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 37
Branch analysis from position: 50
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 37
2 jumps found. (Code = 44) Position 1 = 50, Position 2 = 37
Branch analysis from position: 50
Branch analysis from position: 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 48
Branch analysis from position: 48
filename:       /in/nggja
function name:  reArrange
number of ops:  55
compiled vars:  !0 = $result, !1 = $id, !2 = $new_dev_priority, !3 = $curr_index, !4 = $limit_index, !5 = $process_node, !6 = $curr_dev_priority, !7 = $offset
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   18     3        INIT_FCALL                                               'array_search'
          4        SEND_VAR                                                 !1
          5        INIT_FCALL                                               'array_column'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 'id'
          8        DO_ICALL                                         $8      
          9        SEND_VAR                                                 $8
         10        SEND_VAL                                                 <true>
         11        DO_ICALL                                         $9      
         12        ASSIGN                                                   !3, $9
   19    13        INIT_FCALL                                               'array_search'
         14        SEND_VAR                                                 !2
         15        INIT_FCALL                                               'array_column'
         16        SEND_VAR                                                 !0
         17        SEND_VAL                                                 'dev_priority'
         18        DO_ICALL                                         $11     
         19        SEND_VAR                                                 $11
         20        SEND_VAL                                                 <true>
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !4, $12
   21    23        FETCH_DIM_R                                      ~14     !0, !3
         24        ASSIGN                                                   !5, ~14
   22    25        FETCH_DIM_R                                      ~16     !5, 'dev_priority'
         26        ASSIGN                                                   !6, ~16
   23    27        IS_IDENTICAL                                             !6, !2
         28      > JMPZ                                                     ~18, ->30
         29    > > RETURN                                                   null
   24    30    >   IS_SMALLER                                               !2, !6
         31      > JMPZ                                                     ~19, ->34
         32    >   QM_ASSIGN                                        ~20     -1
         33      > JMP                                                      ->35
         34    >   QM_ASSIGN                                        ~20     1
         35    >   ASSIGN                                                   !7, ~20
   27    36      > JMP                                                      ->48
   28    37    >   ADD                                              ~23     !3, !7
         38        FETCH_DIM_R                                      ~24     !0, ~23
         39        ASSIGN_DIM                                               !0, !3
         40        OP_DATA                                                  ~24
   29    41        FETCH_DIM_R                                      ~27     !0, !3
         42        FETCH_DIM_R                                      ~28     ~27, 'dev_priority'
         43        SUB                                              ~29     ~28, !7
         44        FETCH_DIM_W                                      $25     !0, !3
         45        ASSIGN_DIM                                               $25, 'dev_priority'
         46        OP_DATA                                                  ~29
   30    47        ASSIGN_OP                                     1          !3, !7
   27    48    >   IS_NOT_EQUAL                                             !3, !4
         49      > JMPNZ                                                    ~31, ->37
   33    50    >   ASSIGN_DIM                                               !5, 'dev_priority'
         51        OP_DATA                                                  !2
   34    52        ASSIGN_DIM                                               !0, !3
         53        OP_DATA                                                  !5
   35    54      > RETURN                                                   null

End of function rearrange

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
129.39 ms | 1411 KiB | 20 Q