PHP 8.5.0 Alpha 2 available for testing

Voting

: six minus five?
(Example: nine)

The Note You're Voting On

Bas Vijfwinkel
7 years 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),' '))));

<< Back to user notes page

To Top