I have two integers for example "12345" and "98754", they have a count of 2 matching numbers namely 4 and 5, the order doesnt matter.
Now: How do I check something like that in PHP?
Edit: Code-centric solution:
$a = 1231534;
$b = 89058430;
$matches = compare( $a, $b );
print count($matches);
function compare ( $a, $b ) {
$str_a = (string) $a;
$str_b = (string) $b;
$matches = [];
for($i=0;$i<=9;$i++) {
if (strstr($str_a, (string)$i) && strstr($str_b,(string)$i)) $matches[] = $i;
}
return $matches;
}
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments