3v4l.org

run code in 300+ PHP versions simultaneously
<?php function arr2d_replace_id($arr, $inc) { $result = array(); foreach ($arr['uris'] as $k=>$v) { $result['uris'][intval($k) + $inc] = $v; $result['templates'][intval($k) + $inc] = $arr['templates'][$k]; } return $result; } function arr2d_replace_id2($arr, $inc) { $result = array(); $tpl_flipped = array_flip($arr['templates']); foreach ($arr['uris'] as $k=>$v) { $result['uris'][intval($k) + $inc] = $v; $tpl_flipped[$k] = intval($k) + $inc; } $result['templates'] = array_flip($tpl_flipped); return $result; } $test = array( 'uris' => array( 1 => '/', '/news/', '/about/', '/contact/', ), 'templates' => array( 1 => 1, 2, 3, 4 ) ); print_r( $test ); print_r( arr2d_replace_id($test, 100) ); print_r( arr2d_replace_id2($test, 100) );
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/T6hHD
function name:  (null)
number of ops:  19
compiled vars:  !0 = $test
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   28     0  E >   ASSIGN                                                   !0, <array>
   39     1        INIT_FCALL                                               'print_r'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                                 
   41     4        INIT_FCALL                                               'print_r'
          5        INIT_FCALL                                               'arr2d_replace_id'
          6        SEND_VAR                                                 !0
          7        SEND_VAL                                                 100
          8        DO_FCALL                                      0  $3      
          9        SEND_VAR                                                 $3
         10        DO_ICALL                                                 
   43    11        INIT_FCALL                                               'print_r'
         12        INIT_FCALL                                               'arr2d_replace_id2'
         13        SEND_VAR                                                 !0
         14        SEND_VAL                                                 100
         15        DO_FCALL                                      0  $5      
         16        SEND_VAR                                                 $5
         17        DO_ICALL                                                 
         18      > RETURN                                                   1

Function arr2d_replace_id:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
filename:       /in/T6hHD
function name:  arr2d_replace_id
number of ops:  23
compiled vars:  !0 = $arr, !1 = $inc, !2 = $result, !3 = $v, !4 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    4     2        ASSIGN                                                   !2, <array>
    6     3        FETCH_DIM_R                                      ~6      !0, 'uris'
          4      > FE_RESET_R                                       $7      ~6, ->20
          5    > > FE_FETCH_R                                       ~8      $7, !3, ->20
          6    >   ASSIGN                                                   !4, ~8
    7     7        CAST                                          4  ~11     !4
          8        ADD                                              ~12     ~11, !1
          9        FETCH_DIM_W                                      $10     !2, 'uris'
         10        ASSIGN_DIM                                               $10, ~12
         11        OP_DATA                                                  !3
    8    12        CAST                                          4  ~15     !4
         13        ADD                                              ~16     ~15, !1
         14        FETCH_DIM_R                                      ~18     !0, 'templates'
         15        FETCH_DIM_R                                      ~19     ~18, !4
         16        FETCH_DIM_W                                      $14     !2, 'templates'
         17        ASSIGN_DIM                                               $14, ~16
         18        OP_DATA                                                  ~19
    6    19      > JMP                                                      ->5
         20    >   FE_FREE                                                  $7
   11    21      > RETURN                                                   !2
   12    22*     > RETURN                                                   null

End of function arr2d_replace_id

Function arr2d_replace_id2:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 22
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 22
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/T6hHD
function name:  arr2d_replace_id2
number of ops:  30
compiled vars:  !0 = $arr, !1 = $inc, !2 = $result, !3 = $tpl_flipped, !4 = $v, !5 = $k
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   15     2        ASSIGN                                                   !2, <array>
   16     3        INIT_FCALL                                               'array_flip'
          4        FETCH_DIM_R                                      ~7      !0, 'templates'
          5        SEND_VAL                                                 ~7
          6        DO_ICALL                                         $8      
          7        ASSIGN                                                   !3, $8
   18     8        FETCH_DIM_R                                      ~10     !0, 'uris'
          9      > FE_RESET_R                                       $11     ~10, ->22
         10    > > FE_FETCH_R                                       ~12     $11, !4, ->22
         11    >   ASSIGN                                                   !5, ~12
   19    12        CAST                                          4  ~15     !5
         13        ADD                                              ~16     ~15, !1
         14        FETCH_DIM_W                                      $14     !2, 'uris'
         15        ASSIGN_DIM                                               $14, ~16
         16        OP_DATA                                                  !4
   20    17        CAST                                          4  ~19     !5
         18        ADD                                              ~20     ~19, !1
         19        ASSIGN_DIM                                               !3, !5
         20        OP_DATA                                                  ~20
   18    21      > JMP                                                      ->10
         22    >   FE_FREE                                                  $11
   23    23        INIT_FCALL                                               'array_flip'
         24        SEND_VAR                                                 !3
         25        DO_ICALL                                         $22     
         26        ASSIGN_DIM                                               !2, 'templates'
         27        OP_DATA                                                  $22
   25    28      > RETURN                                                   !2
   26    29*     > RETURN                                                   null

End of function arr2d_replace_id2

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
133.07 ms | 1019 KiB | 17 Q