PHP Anagramm Lösungen

Einfache aber unperformante Lösung:

<?php

function sort_str($str){
    $arr = str_split($str);
    sort($arr );
    return implode($arr);
}

function ana_chk($q_string,$d_string){
    return sort_str($q_string)===sort_str($d_string);
}

function stringAnagram($dictionary, $query) {
    // Write your code here
    $solve = [];
    $i = 0;
    foreach( $query as $q_string ){
        $solve[] = 0;
        foreach( $dictionary as $d_string ){
            $solve[$i] += ana_chk( $q_string,$d_string );
        }
        $i++;
    }

    return $solve;
}

print_r(
    stringAnagram(
        ['heater', 'cold', 'clod', 'reheat', 'docl'],
        ['codl', 'heater', 'abcd']
    )
);