gmp_hamdist

(PHP 4 >= 4.0.4, PHP 5, PHP 7)

gmp_hamdistDistanza dell'hamming

Descrizione

int gmp_hamdist ( resource $a , resource $b )

Restituisce la distanza di hamming tra a e b. Entrambe gli operandi dovrebbero essere non-negativi.

add a note add a note

User Contributed Notes 1 note

up
0
Bas Vijfwinkel
8 days ago
For those without gmp support :

$hamming_distance = count(array_diff_assoc(str_split($string1), str_split($string2)));

And if you are not sure if your strings have equal length :

$hamming_distance = count(array_diff_assoc(str_split(str_pad($string1,strlen($string2)-strlen($string1),' ')), str_split(str_pad($string2,strlen($string1)-strlen($string2),' '))));
To Top