3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr= ["clownfish.jpg", "clownfish-150x150.jpg", "b800-768x575.jpg", "b800-4.jpg", "b800.jpg", "agility_3.jpg", "agility_3-45x45.jpg", "hundezubehör-für-sommer.jpg"]; $find = "hundezubehör-für-sommer.jpg"; var_dump(in_array($find, $arr)); Foreach($arr as $key => $item){ $length = min(strlen($item), strlen($find))-4; // lenght of the smallest string - ".jpg" if(levenshtein(substr($item,0,$length), substr($find,0,$length), 1,1,0) == 0){ //is it the same file $len = [strlen($item) => $item, strlen($find) => $find]; // make a associative array with lenght as key $minkey = min(array_keys($len)); // find the smallest of them $new[] = $len[$minkey]; // add the smallest to the new array } } Var_dump(array_unique($new)); // remove duplicates
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 10, Position 2 = 55
Branch analysis from position: 10
2 jumps found. (Code = 78) Position 1 = 11, Position 2 = 55
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 54
Branch analysis from position: 39
1 jumps found. (Code = 42) Position 1 = 10
Branch analysis from position: 10
Branch analysis from position: 54
Branch analysis from position: 55
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 55
filename:       /in/T7lfU
function name:  (null)
number of ops:  63
compiled vars:  !0 = $arr, !1 = $find, !2 = $item, !3 = $key, !4 = $length, !5 = $len, !6 = $minkey, !7 = $new
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
    7     1        ASSIGN                                                   !1, 'hundezubeh%C3%B6r-f%C3%BCr-sommer.jpg'
    9     2        INIT_FCALL                                               'var_dump'
          3        INIT_FCALL                                               'in_array'
          4        SEND_VAR                                                 !1
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $10     
          7        SEND_VAR                                                 $10
          8        DO_ICALL                                                 
   10     9      > FE_RESET_R                                       $12     !0, ->55
         10    > > FE_FETCH_R                                       ~13     $12, !2, ->55
         11    >   ASSIGN                                                   !3, ~13
   11    12        INIT_FCALL                                               'min'
         13        STRLEN                                           ~15     !2
         14        SEND_VAL                                                 ~15
         15        STRLEN                                           ~16     !1
         16        SEND_VAL                                                 ~16
         17        DO_ICALL                                         $17     
         18        SUB                                              ~18     $17, 4
         19        ASSIGN                                                   !4, ~18
   12    20        INIT_FCALL                                               'levenshtein'
         21        INIT_FCALL                                               'substr'
         22        SEND_VAR                                                 !2
         23        SEND_VAL                                                 0
         24        SEND_VAR                                                 !4
         25        DO_ICALL                                         $20     
         26        SEND_VAR                                                 $20
         27        INIT_FCALL                                               'substr'
         28        SEND_VAR                                                 !1
         29        SEND_VAL                                                 0
         30        SEND_VAR                                                 !4
         31        DO_ICALL                                         $21     
         32        SEND_VAR                                                 $21
         33        SEND_VAL                                                 1
         34        SEND_VAL                                                 1
         35        SEND_VAL                                                 0
         36        DO_ICALL                                         $22     
         37        IS_EQUAL                                                 $22, 0
         38      > JMPZ                                                     ~23, ->54
   13    39    >   STRLEN                                           ~24     !2
         40        INIT_ARRAY                                       ~25     !2, ~24
         41        STRLEN                                           ~26     !1
         42        ADD_ARRAY_ELEMENT                                ~25     !1, ~26
         43        ASSIGN                                                   !5, ~25
   14    44        INIT_FCALL                                               'min'
         45        INIT_FCALL                                               'array_keys'
         46        SEND_VAR                                                 !5
         47        DO_ICALL                                         $28     
         48        SEND_VAR                                                 $28
         49        DO_ICALL                                         $29     
         50        ASSIGN                                                   !6, $29
   15    51        FETCH_DIM_R                                      ~32     !5, !6
         52        ASSIGN_DIM                                               !7
         53        OP_DATA                                                  ~32
   10    54    > > JMP                                                      ->10
         55    >   FE_FREE                                                  $12
   19    56        INIT_FCALL                                               'var_dump'
         57        INIT_FCALL                                               'array_unique'
         58        SEND_VAR                                                 !7
         59        DO_ICALL                                         $33     
         60        SEND_VAR                                                 $33
         61        DO_ICALL                                                 
         62      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
141.3 ms | 1009 KiB | 20 Q