3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = '1234567'; $array = ['1', '12', '123', '1234', '456', '56', '7', '3456', '234567']; $results = []; foreach ($array as $data) { if (strpos($input, $data) === 0) { $results[strlen($data)][] = $data; } } krsort($results); // best results - you can use foreach to scroll them all var_dump($results); // pick the best result echo current($results)[0]; // 1234
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 4, Position 2 = 16
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 16
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 15
Branch analysis from position: 16
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
filename:       /in/o9a41
function name:  (null)
number of ops:  29
compiled vars:  !0 = $input, !1 = $array, !2 = $results, !3 = $data
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, '1234567'
    4     1        ASSIGN                                                   !1, <array>
    6     2        ASSIGN                                                   !2, <array>
    7     3      > FE_RESET_R                                       $7      !1, ->16
          4    > > FE_FETCH_R                                               $7, !3, ->16
    8     5    >   INIT_FCALL                                               'strpos'
          6        SEND_VAR                                                 !0
          7        SEND_VAR                                                 !3
          8        DO_ICALL                                         $8      
          9        IS_IDENTICAL                                             $8, 0
         10      > JMPZ                                                     ~9, ->15
    9    11    >   STRLEN                                           ~10     !3
         12        FETCH_DIM_W                                      $11     !2, ~10
         13        ASSIGN_DIM                                               $11
         14        OP_DATA                                                  !3
    7    15    > > JMP                                                      ->4
         16    >   FE_FREE                                                  $7
   13    17        INIT_FCALL                                               'krsort'
         18        SEND_REF                                                 !2
         19        DO_ICALL                                                 
   16    20        INIT_FCALL                                               'var_dump'
         21        SEND_VAR                                                 !2
         22        DO_ICALL                                                 
   19    23        INIT_FCALL                                               'current'
         24        SEND_VAR                                                 !2
         25        DO_ICALL                                         $15     
         26        FETCH_DIM_R                                      ~16     $15, 0
         27        ECHO                                                     ~16
         28      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.56 ms | 1396 KiB | 21 Q