3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Return the coefficient of two items based on Jaccard index * http://en.wikipedia.org/wiki/Jaccard_index * * Example: * * $tags1 = "code, php, jaccard, test, items"; * $tags2 = "test, code"; * echo getSimilarityCoefficient( $tags1, $tags2 ); // 0.28 * * $str1 = "similarity coefficient of two items"; * $str2 = "two items are cool"; * echo getSimilarityCoefficient( $str1, $str2, " " ); // 0.44 * * @param string $item1 * @param string $item2 * @param string $separator * @return float * @author Henrique Hohmann * @version 0.1 */ function getSimilarityCoefficient( $item1, $item2, $separator = "," ) { $item1 = explode( $separator, $item1 ); $item2 = explode( $separator, $item2 ); $arr_intersection = array_intersect( $item2, $item2 ); $arr_union = array_merge( $item1, $item2 ); $coefficient = count( $arr_intersection ) / count( $arr_union ); return $coefficient; } print(getSimilarityCoefficient('SA PRESTASHOP', strtoupper('PrestaShop SA')));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WlJ1Q
function name:  (null)
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   35     0  E >   INIT_FCALL                                               'getsimilaritycoefficient'
          1        SEND_VAL                                                 'SA+PRESTASHOP'
          2        INIT_FCALL                                               'strtoupper'
          3        SEND_VAL                                                 'PrestaShop+SA'
          4        DO_ICALL                                         $0      
          5        SEND_VAR                                                 $0
          6        DO_FCALL                                      0  $1      
          7        ECHO                                                     $1
          8      > RETURN                                                   1

Function getsimilaritycoefficient:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/WlJ1Q
function name:  getSimilarityCoefficient
number of ops:  29
compiled vars:  !0 = $item1, !1 = $item2, !2 = $separator, !3 = $arr_intersection, !4 = $arr_union, !5 = $coefficient
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   24     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV_INIT                                        !2      '%2C'
   26     3        INIT_FCALL                                               'explode'
          4        SEND_VAR                                                 !2
          5        SEND_VAR                                                 !0
          6        DO_ICALL                                         $6      
          7        ASSIGN                                                   !0, $6
   27     8        INIT_FCALL                                               'explode'
          9        SEND_VAR                                                 !2
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $8      
         12        ASSIGN                                                   !1, $8
   28    13        INIT_FCALL                                               'array_intersect'
         14        SEND_VAR                                                 !1
         15        SEND_VAR                                                 !1
         16        DO_ICALL                                         $10     
         17        ASSIGN                                                   !3, $10
   29    18        INIT_FCALL                                               'array_merge'
         19        SEND_VAR                                                 !0
         20        SEND_VAR                                                 !1
         21        DO_ICALL                                         $12     
         22        ASSIGN                                                   !4, $12
   30    23        COUNT                                            ~14     !3
         24        COUNT                                            ~15     !4
         25        DIV                                              ~16     ~14, ~15
         26        ASSIGN                                                   !5, ~16
   32    27      > RETURN                                                   !5
   33    28*     > RETURN                                                   null

End of function getsimilaritycoefficient

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
182.95 ms | 1399 KiB | 22 Q