3v4l.org

run code in 500+ 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 = 13
Branch analysis from position: 4
2 jumps found. (Code = 78) Position 1 = 5, Position 2 = 13
Branch analysis from position: 5
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 12
Branch analysis from position: 8
1 jumps found. (Code = 42) Position 1 = 4
Branch analysis from position: 4
Branch analysis from position: 12
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
filename:       /in/o9a41
function name:  (null)
number of ops:  26
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, ->13
          4    > > FE_FETCH_R                                                   $7, !3, ->13
    8     5    >   FRAMELESS_ICALL_2                strpos              ~8      !0, !3
          6        IS_IDENTICAL                                                 ~8, 0
          7      > JMPZ                                                         ~9, ->12
    9     8    >   STRLEN                                               ~10     !3
          9        FETCH_DIM_W                                          $11     !2, ~10
         10        ASSIGN_DIM                                                   $11
         11        OP_DATA                                                      !3
    7    12    > > JMP                                                          ->4
         13    >   FE_FREE                                                      $7
   13    14        INIT_FCALL                                                   'krsort'
         15        SEND_REF                                                     !2
         16        DO_ICALL                                                     
   16    17        INIT_FCALL                                                   'var_dump'
         18        SEND_VAR                                                     !2
         19        DO_ICALL                                                     
   19    20        INIT_FCALL                                                   'current'
         21        SEND_VAR                                                     !2
         22        DO_ICALL                                             $15     
         23        FETCH_DIM_R                                          ~16     $15, 0
         24        ECHO                                                         ~16
         25      > RETURN                                                       1

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
162.55 ms | 2698 KiB | 16 Q