3v4l.org

run code in 300+ PHP versions simultaneously
<?php $area_codes = array( '015019', '015020', '01511', '01512', '01514', '01515', '01516', '01517', '015180', '015181', '015182', '015183', '015184', '015185', ); // Build an associative array $area_lookup = []; foreach($area_codes as $code) $area_lookup[$code] = 1; function splitNumber(array $area_lookup, string $telephone_number): array { for($len=4;$len<=6;$len++) { $prefix = substr($telephone_number, 0, $len); if(isset($area_lookup[$prefix])) return ['area_code' => $prefix, 'subscriber_number' => substr($telephone_number, $len)]; } throw new Exception('Invalid number'); } $res1 = splitNumber($area_lookup, '015169999999'); $res2 = splitNumber($area_lookup, '015180999999'); var_dump($res1, $res2);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/Iajsp
function name:  (null)
number of ops:  23
compiled vars:  !0 = $area_codes, !1 = $area_lookup, !2 = $code, !3 = $res1, !4 = $res2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
   20     1        ASSIGN                                                   !1, <array>
   21     2      > FE_RESET_R                                       $7      !0, ->7
          3    > > FE_FETCH_R                                               $7, !2, ->7
   22     4    >   ASSIGN_DIM                                               !1, !2
          5        OP_DATA                                                  1
   21     6      > JMP                                                      ->3
          7    >   FE_FREE                                                  $7
   35     8        INIT_FCALL                                               'splitnumber'
          9        SEND_VAR                                                 !1
         10        SEND_VAL                                                 '015169999999'
         11        DO_FCALL                                      0  $9      
         12        ASSIGN                                                   !3, $9
   36    13        INIT_FCALL                                               'splitnumber'
         14        SEND_VAR                                                 !1
         15        SEND_VAL                                                 '015180999999'
         16        DO_FCALL                                      0  $11     
         17        ASSIGN                                                   !4, $11
   37    18        INIT_FCALL                                               'var_dump'
         19        SEND_VAR                                                 !3
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                                 
         22      > RETURN                                                   1

Function splitnumber:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 21
Branch analysis from position: 21
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
1 jumps found. (Code = 108) Position 1 = -2
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 12, Position 2 = 20
Branch analysis from position: 12
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 20
2 jumps found. (Code = 44) Position 1 = 23, Position 2 = 4
Branch analysis from position: 23
Branch analysis from position: 4
filename:       /in/Iajsp
function name:  splitNumber
number of ops:  29
compiled vars:  !0 = $area_lookup, !1 = $telephone_number, !2 = $len, !3 = $prefix
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   26     2        ASSIGN                                                   !2, 4
          3      > JMP                                                      ->21
   28     4    >   INIT_FCALL                                               'substr'
          5        SEND_VAR                                                 !1
          6        SEND_VAL                                                 0
          7        SEND_VAR                                                 !2
          8        DO_ICALL                                         $5      
          9        ASSIGN                                                   !3, $5
   29    10        ISSET_ISEMPTY_DIM_OBJ                         0          !0, !3
         11      > JMPZ                                                     ~7, ->20
   30    12    >   INIT_ARRAY                                       ~8      !3, 'area_code'
         13        INIT_FCALL                                               'substr'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !2
         16        DO_ICALL                                         $9      
         17        ADD_ARRAY_ELEMENT                                ~8      $9, 'subscriber_number'
         18        VERIFY_RETURN_TYPE                                       ~8
         19      > RETURN                                                   ~8
   26    20    >   PRE_INC                                                  !2
         21    >   IS_SMALLER_OR_EQUAL                                      !2, 6
         22      > JMPNZ                                                    ~11, ->4
   32    23    >   NEW                                              $12     'Exception'
         24        SEND_VAL_EX                                              'Invalid+number'
         25        DO_FCALL                                      0          
         26      > THROW                                         0          $12
   33    27*       VERIFY_RETURN_TYPE                                       
         28*     > RETURN                                                   null

End of function splitnumber

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
146.7 ms | 1018 KiB | 17 Q