3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arrayA=[ 'Red', 'Black', 'White', 'Green' ]; $arrayB=[ 'Blackwell', 'Purple', 'Whitewater', 'Reddit' ]; // similar text foreach($arrayA as $a){ $temp=array_combine($arrayB,array_map(function($v)use($a){similar_text($v,$a,$percent); return $percent;},$arrayB)); // generate assoc array of assessments arsort($temp); // sort descending $result[]="$a is most similar to ".key($temp)." (sim-score:".number_format(current($temp))."%)"; // access first key and value } var_export($result); echo "\n--\n"; // levenstein doesn't offer the desired matching foreach($arrayA as $a){ $temp=array_combine($arrayB,array_map(function($v)use($a){return levenshtein($v,$a);},$arrayB)); // generate assoc array of assessments arsort($temp); // sort descending $result2[]="$a is most similar to ".key($temp)." (lev-score:".current($temp).")"; // access first key and value } var_export($result2);
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 36
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 36
Branch analysis from position: 4
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 36
2 jumps found. (Code = 77) Position 1 = 42, Position 2 = 72
Branch analysis from position: 42
2 jumps found. (Code = 78) Position 1 = 43, Position 2 = 72
Branch analysis from position: 43
1 jumps found. (Code = 42) Position 1 = 42
Branch analysis from position: 42
Branch analysis from position: 72
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 72
Branch analysis from position: 36
filename:       /in/DRQfH
function name:  (null)
number of ops:  77
compiled vars:  !0 = $arrayA, !1 = $arrayB, !2 = $a, !3 = $temp, !4 = $result, !5 = $result2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    2     0  E >   ASSIGN                                                   !0, <array>
    8     1        ASSIGN                                                   !1, <array>
   16     2      > FE_RESET_R                                       $8      !0, ->36
          3    > > FE_FETCH_R                                               $8, !2, ->36
   17     4    >   INIT_FCALL                                               'array_combine'
          5        SEND_VAR                                                 !1
          6        INIT_FCALL                                               'array_map'
          7        DECLARE_LAMBDA_FUNCTION                          ~9      [0]
          8        BIND_LEXICAL                                             ~9, !2
          9        SEND_VAL                                                 ~9
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $10     
         12        SEND_VAR                                                 $10
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !3, $11
   18    15        INIT_FCALL                                               'arsort'
         16        SEND_REF                                                 !3
         17        DO_ICALL                                                 
   19    18        NOP                                                      
         19        FAST_CONCAT                                      ~15     !2, '+is+most+similar+to+'
         20        INIT_FCALL                                               'key'
         21        SEND_VAR                                                 !3
         22        DO_ICALL                                         $16     
         23        CONCAT                                           ~17     ~15, $16
         24        CONCAT                                           ~18     ~17, '+%28sim-score%3A'
         25        INIT_FCALL                                               'number_format'
         26        INIT_FCALL                                               'current'
         27        SEND_VAR                                                 !3
         28        DO_ICALL                                         $19     
         29        SEND_VAR                                                 $19
         30        DO_ICALL                                         $20     
         31        CONCAT                                           ~21     ~18, $20
         32        CONCAT                                           ~22     ~21, '%25%29'
         33        ASSIGN_DIM                                               !4
         34        OP_DATA                                                  ~22
   16    35      > JMP                                                      ->3
         36    >   FE_FREE                                                  $8
   21    37        INIT_FCALL                                               'var_export'
         38        SEND_VAR                                                 !4
         39        DO_ICALL                                                 
   23    40        ECHO                                                     '%0A--%0A'
   25    41      > FE_RESET_R                                       $24     !0, ->72
         42    > > FE_FETCH_R                                               $24, !2, ->72
   26    43    >   INIT_FCALL                                               'array_combine'
         44        SEND_VAR                                                 !1
         45        INIT_FCALL                                               'array_map'
         46        DECLARE_LAMBDA_FUNCTION                          ~25     [1]
         47        BIND_LEXICAL                                             ~25, !2
         48        SEND_VAL                                                 ~25
         49        SEND_VAR                                                 !1
         50        DO_ICALL                                         $26     
         51        SEND_VAR                                                 $26
         52        DO_ICALL                                         $27     
         53        ASSIGN                                                   !3, $27
   27    54        INIT_FCALL                                               'arsort'
         55        SEND_REF                                                 !3
         56        DO_ICALL                                                 
   28    57        NOP                                                      
         58        FAST_CONCAT                                      ~31     !2, '+is+most+similar+to+'
         59        INIT_FCALL                                               'key'
         60        SEND_VAR                                                 !3
         61        DO_ICALL                                         $32     
         62        CONCAT                                           ~33     ~31, $32
         63        CONCAT                                           ~34     ~33, '+%28lev-score%3A'
         64        INIT_FCALL                                               'current'
         65        SEND_VAR                                                 !3
         66        DO_ICALL                                         $35     
         67        CONCAT                                           ~36     ~34, $35
         68        CONCAT                                           ~37     ~36, '%29'
         69        ASSIGN_DIM                                               !5
         70        OP_DATA                                                  ~37
   25    71      > JMP                                                      ->42
         72    >   FE_FREE                                                  $24
   30    73        INIT_FCALL                                               'var_export'
         74        SEND_VAR                                                 !5
         75        DO_ICALL                                                 
         76      > RETURN                                                   1


Dynamic Functions:
Dynamic Function 0
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DRQfH
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $v, !1 = $a, !2 = $percent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'similar_text'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        SEND_REF                                                 !2
          6        DO_ICALL                                                 
          7      > RETURN                                                   !2
          8*     > RETURN                                                   null

End of Dynamic Function 0

Dynamic Function 1
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/DRQfH
function name:  {closure}
number of ops:  8
compiled vars:  !0 = $v, !1 = $a
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
          1        BIND_STATIC                                              !1
          2        INIT_FCALL                                               'levenshtein'
          3        SEND_VAR                                                 !0
          4        SEND_VAR                                                 !1
          5        DO_ICALL                                         $2      
          6      > RETURN                                                   $2
          7*     > RETURN                                                   null

End of Dynamic Function 1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
160.11 ms | 1028 KiB | 22 Q