Answer the question
In order to leave comments, you need to log in
How to compare two arrays percentage similarity?
Let's say I have two arrays
$arr[0]= "a";
$arr[1]= "q";
$arr[2]= "w";
$arr[3]= "e";
$arr[4]= "r";
$arr2[0]= "1";
$arr2[1]= "a";
$arr2[2]= "12";
$arr2[3]= "q";
array_intersect($arr, $arr2);
Answer the question
In order to leave comments, you need to log in
You can do so.
$arr1 = [1,2,3,4,5,6,7,8,9,10];
$arr2 = [2,3];
$arr3 = array_diff($arr1, $arr2);
$undiff_count = count($arr1) - count($arr3); //Нужно число выкинутых, а не оставшихся
$similiar_count = $undiff_count * 100 / count($arr1);
echo 'Схожесть массивов ' . $similiar_count .'%';
The similarity of two arrays is the arithmetic mean. (A + B) / 2.
You have already deduced the similarity of one with the other.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question