You can do something like this.
$a = 'apple';
$b = 'ball';
$duplicates = array_count_values(array_merge(str_split($a), str_split($b)));
// Array ( [a] => 2 [p] => 2 [l] => 3 [e] => 1 [b] => 1 )
print_r($duplicates);
If you want to get the total number of matches among the words, you could then do this.
$totalMatches = 0;
foreach($duplicates as $count) {
if($count > 1)
$totalMatches += $count;
}
// 7 matches!
echo $totalMatches . ' matches!';