3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1234567'; $array = ['1', '12', '123', '1234', '456', '56', '7', '3456', '234567']; function get_best_prefix($input, $array, $limit = -1, &$count){ $best = ''; $sizeBest = 0; foreach ($array as $data) { if (strpos($input, $data) === 0) { $current = strlen($data); if($sizeBest < $current){ $sizeBest = $current; $best = $data; } } } return $best; } echo get_best_prefix($input, $array);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/p5ai7
function name:  (null)
number of ops:  8
compiled vars:  !0 = $input, !1 = $array
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '1234567'
    4     1        ASSIGN                                                   !1, <array>
   26     2        INIT_FCALL                                               'get_best_prefix'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_FCALL                                      0  $4      
          6        ECHO                                                     $4
          7      > RETURN                                                   1

Function get_best_prefix:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 7, Position 2 = 21
Branch analysis from position: 7
2 jumps found. (Code = 78) Position 1 = 8, Position 2 = 21
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 14, Position 2 = 20
Branch analysis from position: 14
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 20
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 7
Branch analysis from position: 7
Branch analysis from position: 20
Branch analysis from position: 20
Branch analysis from position: 21
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 21
filename:       /in/p5ai7
function name:  get_best_prefix
number of ops:  24
compiled vars:  !0 = $input, !1 = $array, !2 = $limit, !3 = $count, !4 = $best, !5 = $sizeBest, !6 = $data, !7 = $current
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      -1
          3        RECV                                             !3      
    9     4        ASSIGN                                                   !4, ''
   10     5        ASSIGN                                                   !5, 0
   12     6      > FE_RESET_R                                       $10     !1, ->21
          7    > > FE_FETCH_R                                               $10, !6, ->21
   13     8    >   INIT_FCALL                                               'strpos'
          9        SEND_VAR                                                 !0
         10        SEND_VAR                                                 !6
         11        DO_ICALL                                         $11     
         12        IS_IDENTICAL                                             $11, 0
         13      > JMPZ                                                     ~12, ->20
   14    14    >   STRLEN                                           ~13     !6
         15        ASSIGN                                                   !7, ~13
   15    16        IS_SMALLER                                               !5, !7
         17      > JMPZ                                                     ~15, ->20
   16    18    >   ASSIGN                                                   !5, !7
   17    19        ASSIGN                                                   !4, !6
   12    20    > > JMP                                                      ->7
         21    >   FE_FREE                                                  $10
   22    22      > RETURN                                                   !4
   24    23*     > RETURN                                                   null

End of function get_best_prefix

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
168 ms | 1403 KiB | 16 Q