3v4l.org

run code in 300+ PHP versions simultaneously
<?php $companies = array( array('id' => '1','name' => 'Fifo Limited'), array('id' => '2','name' => 'FIFO Ltd'), array('id' => '3','name' => 'BitBytes Ltd'), array('id' => '4','name' => 'Info Sys'), array('id' => '5','name' => 'DevSquad'), array('id' => '6','name' => 'IT Magnet'), // 2/9 = 22% < 30% array('id' => '7','name' => 'Fifo-IT'), array('id' => '8','name' => 'Others'), array('id' => '9','name' => 'IT M2'), // 2/4 = 50% //array('id' => '10','name' => 'IT M3'), // 2/4 = 50% ); $percentage = 0.3; function getSimilarities($data, $pers){ $result = []; $tmp = []; foreach($data as $ind => &$record){ // split string by special chars '-' or ' ', array $name = preg_split('/[- ]/',$record['name']); // makes first word to lowercase $record['lowercase'] = strtolower($name[0]); // first word length $record['strlength_first'] = strlen($record['lowercase']); // string length $record['strlength_full'] = strlen($record['name']); // if length > 0 if ($record['strlength_full'] && // and if length of forst word > 30% string length $record['strlength_first']/$record['strlength_full'] >= $pers){ $input = preg_quote($record['lowercase'], '~'); if(preg_grep('~'.$input.'~', $record)) $tmp[$record['lowercase']][] = $record['id']; } } // if more than 1 = similar names foreach($tmp as $key=>$matches){ if (count($matches)>1){ $result[$key] = $matches; } } return $result; } print_r(getSimilarities($companies, $percentage));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/2FOLZ
function name:  (null)
number of ops:  10
compiled vars:  !0 = $companies, !1 = $percentage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   ASSIGN                                                   !0, <array>
   16     1        ASSIGN                                                   !1, 0.3
   58     2        INIT_FCALL                                               'print_r'
          3        INIT_FCALL                                               'getsimilarities'
          4        SEND_VAR                                                 !0
          5        SEND_VAR                                                 !1
          6        DO_FCALL                                      0  $4      
          7        SEND_VAR                                                 $4
          8        DO_ICALL                                                 
          9      > RETURN                                                   1

Function getsimilarities:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 125) Position 1 = 5, Position 2 = 54
Branch analysis from position: 5
2 jumps found. (Code = 126) Position 1 = 6, Position 2 = 54
Branch analysis from position: 6
2 jumps found. (Code = 46) Position 1 = 29, Position 2 = 34
Branch analysis from position: 29
2 jumps found. (Code = 43) Position 1 = 35, Position 2 = 53
Branch analysis from position: 35
2 jumps found. (Code = 43) Position 1 = 48, Position 2 = 53
Branch analysis from position: 48
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 53
Branch analysis from position: 53
Branch analysis from position: 34
Branch analysis from position: 54
2 jumps found. (Code = 77) Position 1 = 56, Position 2 = 64
Branch analysis from position: 56
2 jumps found. (Code = 78) Position 1 = 57, Position 2 = 64
Branch analysis from position: 57
2 jumps found. (Code = 43) Position 1 = 61, Position 2 = 63
Branch analysis from position: 61
1 jumps found. (Code = 42) Position 1 = 56
Branch analysis from position: 56
Branch analysis from position: 63
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
Branch analysis from position: 54
filename:       /in/2FOLZ
function name:  getSimilarities
number of ops:  67
compiled vars:  !0 = $data, !1 = $pers, !2 = $result, !3 = $tmp, !4 = $record, !5 = $ind, !6 = $name, !7 = $input, !8 = $matches, !9 = $key
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   20     2        ASSIGN                                                   !2, <array>
   21     3        ASSIGN                                                   !3, <array>
   23     4      > FE_RESET_RW                                      $12     !0, ->54
          5    > > FE_FETCH_RW                                      ~13     $12, !4, ->54
          6    >   ASSIGN                                                   !5, ~13
   25     7        INIT_FCALL                                               'preg_split'
          8        SEND_VAL                                                 '%2F%5B-+%5D%2F'
          9        FETCH_DIM_R                                      ~15     !4, 'name'
         10        SEND_VAL                                                 ~15
         11        DO_ICALL                                         $16     
         12        ASSIGN                                                   !6, $16
   28    13        INIT_FCALL                                               'strtolower'
         14        FETCH_DIM_R                                      ~19     !6, 0
         15        SEND_VAL                                                 ~19
         16        DO_ICALL                                         $20     
         17        ASSIGN_DIM                                               !4, 'lowercase'
         18        OP_DATA                                                  $20
   31    19        FETCH_DIM_R                                      ~22     !4, 'lowercase'
         20        STRLEN                                           ~23     ~22
         21        ASSIGN_DIM                                               !4, 'strlength_first'
         22        OP_DATA                                                  ~23
   34    23        FETCH_DIM_R                                      ~25     !4, 'name'
         24        STRLEN                                           ~26     ~25
         25        ASSIGN_DIM                                               !4, 'strlength_full'
         26        OP_DATA                                                  ~26
   37    27        FETCH_DIM_R                                      ~27     !4, 'strlength_full'
         28      > JMPZ_EX                                          ~27     ~27, ->34
   39    29    >   FETCH_DIM_R                                      ~28     !4, 'strlength_first'
         30        FETCH_DIM_R                                      ~29     !4, 'strlength_full'
         31        DIV                                              ~30     ~28, ~29
         32        IS_SMALLER_OR_EQUAL                              ~31     !1, ~30
         33        BOOL                                             ~27     ~31
         34    > > JMPZ                                                     ~27, ->53
   41    35    >   INIT_FCALL                                               'preg_quote'
         36        FETCH_DIM_R                                      ~32     !4, 'lowercase'
         37        SEND_VAL                                                 ~32
         38        SEND_VAL                                                 '%7E'
         39        DO_ICALL                                         $33     
         40        ASSIGN                                                   !7, $33
   43    41        INIT_FCALL                                               'preg_grep'
         42        CONCAT                                           ~35     '%7E', !7
         43        CONCAT                                           ~36     ~35, '%7E'
         44        SEND_VAL                                                 ~36
         45        SEND_VAR                                                 !4
         46        DO_ICALL                                         $37     
         47      > JMPZ                                                     $37, ->53
   44    48    >   FETCH_DIM_R                                      ~38     !4, 'lowercase'
         49        FETCH_DIM_R                                      ~41     !4, 'id'
         50        FETCH_DIM_W                                      $39     !3, ~38
         51        ASSIGN_DIM                                               $39
         52        OP_DATA                                                  ~41
   23    53    > > JMP                                                      ->5
         54    >   FE_FREE                                                  $12
   49    55      > FE_RESET_R                                       $42     !3, ->64
         56    > > FE_FETCH_R                                       ~43     $42, !8, ->64
         57    >   ASSIGN                                                   !9, ~43
   50    58        COUNT                                            ~45     !8
         59        IS_SMALLER                                               1, ~45
         60      > JMPZ                                                     ~46, ->63
   51    61    >   ASSIGN_DIM                                               !2, !9
         62        OP_DATA                                                  !8
   49    63    > > JMP                                                      ->56
         64    >   FE_FREE                                                  $42
   55    65      > RETURN                                                   !2
   56    66*     > RETURN                                                   null

End of function getsimilarities

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
138.39 ms | 1015 KiB | 19 Q