Determining duplicate letter counts between an array of strings
<p>I have an array of strings of random letters, and I need to know which letters are consistent between the array members. The count of the letters are important.</p>

<p>My method right now is loop through the array, doing a split, then looping through the spitted string to count the occurrences of each letter, then update the array with <code>letter =&gt; count</code> </p>

<p>Then do an array_reduce that creates a new array of members who only occur in all arrays. But, it's not working.</p>

<pre><code>&lt;?
$a[] = "emaijuqqrauw";
$a[] = "aaeggimqruuz";
$a[] = "aabimqrtuuzw";
$a[] = "aacikmqruuxz";
$a[] = "aacikmqruuxz";
$a[] = "aaciimqruuxy";

foreach($a as $b){
    $n = str_split($b, 1);
    foreach($n as $z){
        $arr[$z] = substr_count($b, $z);
    }
    ksort($arr);
    $array[] = $arr;
    unset($arr);
}

$n = array_reduce($array, function($result, $item){
    if($result === null){
        return $item;
    }else{
        foreach($item as $key =&gt; $val){
            if(isset($result[$key])){
                $new[$key] = $val;
            }
        }
        return $new;
    }
});

foreach($n as $key =&gt; $val){
    echo str_repeat($key, $val);
}
</code></pre>

<p>This returns <code>aaiimqruu</code> - which is kinda right, but there's only 2 <code>i</code>'s in the last element of the array. There's only one <code>i</code> in the rest. I'm not sure how to break that down farther and get it to return <code>aaimqruu</code>- which I'll then pop into a SQL query to find a matching word, <code>aquarium</code></p>
