3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array(670006151,670006152,670006251); function getPrefixedData($arr){ if(count($arr) == 0) return []; $longest_prefix = strval($arr[0]); foreach($arr as $val){ $val = strval($val); $len = strlen($longest_prefix); for($i=0;$i<$len;++$i){ if($longest_prefix[$i] != $val[$i]){ $longest_prefix = substr($longest_prefix,0,$i); break; } } } $res = []; $len = strlen($longest_prefix); foreach($arr as $index => $val){ if($index == 0) $res[] = $longest_prefix . substr(strval($val),$len); else $res[] = substr(strval($val),$len); } return $res; } print_r(getPrefixedData([670006151,670006152,670006251])); print_r(getPrefixedData([670006151,670006154,670006158])); print_r(getPrefixedData([670006151,670006154,670006161])); print_r(getPrefixedData([670006151,670006154,7])); print_r(getPrefixedData([8,8,8]));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/UHTf7
function name:  (null)
number of ops:  32
compiled vars:  !0 = $arr
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   31     1        INIT_FCALL                                               'print_r'
          2        INIT_FCALL                                               'getprefixeddata'
          3        SEND_VAL                                                 <array>
          4        DO_FCALL                                      0  $2      
          5        SEND_VAR                                                 $2
          6        DO_ICALL                                                 
   32     7        INIT_FCALL                                               'print_r'
          8        INIT_FCALL                                               'getprefixeddata'
          9        SEND_VAL                                                 <array>
         10        DO_FCALL                                      0  $4      
         11        SEND_VAR                                                 $4
         12        DO_ICALL                                                 
   33    13        INIT_FCALL                                               'print_r'
         14        INIT_FCALL                                               'getprefixeddata'
         15        SEND_VAL                                                 <array>
         16        DO_FCALL                                      0  $6      
         17        SEND_VAR                                                 $6
         18        DO_ICALL                                                 
   34    19        INIT_FCALL                                               'print_r'
         20        INIT_FCALL                                               'getprefixeddata'
         21        SEND_VAL                                                 <array>
         22        DO_FCALL                                      0  $8      
         23        SEND_VAR                                                 $8
         24        DO_ICALL                                                 
   35    25        INIT_FCALL                                               'print_r'
         26        INIT_FCALL                                               'getprefixeddata'
         27        SEND_VAL                                                 <array>
         28        DO_FCALL                                      0  $10     
         29        SEND_VAR                                                 $10
         30        DO_ICALL                                                 
         31      > RETURN                                                   1

Function getprefixeddata:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 5
Branch analysis from position: 4
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 31
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 31
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 16
Branch analysis from position: 30
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 20, Position 2 = 27
Branch analysis from position: 20
1 jumps found. (Code = 42) Position 1 = 30
Branch analysis from position: 30
Branch analysis from position: 27
2 jumps found. (Code = 44) Position 1 = 30, Position 2 = 16
Branch analysis from position: 30
Branch analysis from position: 16
Branch analysis from position: 31
2 jumps found. (Code = 77) Position 1 = 36, Position 2 = 57
Branch analysis from position: 36
2 jumps found. (Code = 78) Position 1 = 37, Position 2 = 57
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 40, Position 2 = 49
Branch analysis from position: 40
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 49
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
Branch analysis from position: 57
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 57
Branch analysis from position: 31
filename:       /in/UHTf7
function name:  getPrefixedData
number of ops:  60
compiled vars:  !0 = $arr, !1 = $longest_prefix, !2 = $val, !3 = $len, !4 = $i, !5 = $res, !6 = $index
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   RECV                                             !0      
    7     1        COUNT                                            ~7      !0
          2        IS_EQUAL                                                 ~7, 0
          3      > JMPZ                                                     ~8, ->5
          4    > > RETURN                                                   <array>
    8     5    >   FETCH_DIM_R                                      ~9      !0, 0
          6        CAST                                          6  ~10     ~9
          7        ASSIGN                                                   !1, ~10
    9     8      > FE_RESET_R                                       $12     !0, ->31
          9    > > FE_FETCH_R                                               $12, !2, ->31
   10    10    >   CAST                                          6  ~13     !2
         11        ASSIGN                                                   !2, ~13
   11    12        STRLEN                                           ~15     !1
         13        ASSIGN                                                   !3, ~15
   12    14        ASSIGN                                                   !4, 0
         15      > JMP                                                      ->28
   13    16    >   FETCH_DIM_R                                      ~18     !1, !4
         17        FETCH_DIM_R                                      ~19     !2, !4
         18        IS_NOT_EQUAL                                             ~18, ~19
         19      > JMPZ                                                     ~20, ->27
   14    20    >   INIT_FCALL                                               'substr'
         21        SEND_VAR                                                 !1
         22        SEND_VAL                                                 0
         23        SEND_VAR                                                 !4
         24        DO_ICALL                                         $21     
         25        ASSIGN                                                   !1, $21
   15    26      > JMP                                                      ->30
   12    27    >   PRE_INC                                                  !4
         28    >   IS_SMALLER                                               !4, !3
         29      > JMPNZ                                                    ~24, ->16
    9    30    > > JMP                                                      ->9
         31    >   FE_FREE                                                  $12
   20    32        ASSIGN                                                   !5, <array>
   21    33        STRLEN                                           ~26     !1
         34        ASSIGN                                                   !3, ~26
   22    35      > FE_RESET_R                                       $28     !0, ->57
         36    > > FE_FETCH_R                                       ~29     $28, !2, ->57
         37    >   ASSIGN                                                   !6, ~29
   23    38        IS_EQUAL                                                 !6, 0
         39      > JMPZ                                                     ~31, ->49
         40    >   INIT_FCALL                                               'substr'
         41        CAST                                          6  ~33     !2
         42        SEND_VAL                                                 ~33
         43        SEND_VAR                                                 !3
         44        DO_ICALL                                         $34     
         45        CONCAT                                           ~35     !1, $34
         46        ASSIGN_DIM                                               !5
         47        OP_DATA                                                  ~35
         48      > JMP                                                      ->56
   24    49    >   INIT_FCALL                                               'substr'
         50        CAST                                          6  ~37     !2
         51        SEND_VAL                                                 ~37
         52        SEND_VAR                                                 !3
         53        DO_ICALL                                         $38     
         54        ASSIGN_DIM                                               !5
         55        OP_DATA                                                  $38
   22    56    > > JMP                                                      ->36
         57    >   FE_FREE                                                  $28
   27    58      > RETURN                                                   !5
   28    59*     > RETURN                                                   null

End of function getprefixeddata

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.26 ms | 1017 KiB | 20 Q