Find same characters in 2 strings
I would recommend a process like this:

Code: (Demo)

$string1 = "abacadeee";
$string2 = "aabbccddee";

$counts2 = count_chars($string2, 1);

$tally = 0;
foreach (array_intersect_key(count_chars($string1, 1), $counts2) as $charcode1 =&gt; $count1) {
    $tally += min($counts2[$charcode1], $count1);
}
echo $tally;


count_chars() lends itself beautifully to this task, so using array functions onward is a sensible choice.

It is important to try to minimize iterations and not perform any useless iterations.  By calling array_intersect_key() on the two count_chars() results, the foreach() loop is only going to iterate elements with keys which are shared between the two arrays.  In doing this, you don't need to check which array is smaller (which is otherwise how you would choose which array to iterate).

$tally is incremented by the lesser of the two counts for each char.

p.s. calling chr() is irrelevant to your objective.