Sha256: 92df8e0b4348b43f1d7a72b1cfa1dbcc73c87741ed730e753ee7086eb3797be0

Contents?: true

Size: 767 Bytes

Versions: 396

Compression:

Stored size: 767 Bytes

Contents

<?php

function detectAnagrams($anagram, array $possibleMatches)
{
    $matches = [];

    foreach ($possibleMatches as $possibleMatch) {
        $anagramLetters = str_split(mb_strtolower($anagram));
        $matchLetters = str_split(mb_strtolower($possibleMatch));

        if (count($anagramLetters) === count($matchLetters) and $anagramLetters !== $matchLetters) {
            foreach ($matchLetters as $character) {
                $index = array_search($character, $anagramLetters);

                if ($index !== false) {
                    unset($anagramLetters[$index]);
                }

                if (empty($anagramLetters)) {
                    $matches[] = $possibleMatch;
                }
            }
        }
    }

    return $matches;
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/php/exercises/anagram/example.php
trackler-2.2.1.179 tracks/php/exercises/anagram/example.php
trackler-2.2.1.178 tracks/php/exercises/anagram/example.php
trackler-2.2.1.177 tracks/php/exercises/anagram/example.php
trackler-2.2.1.176 tracks/php/exercises/anagram/example.php
trackler-2.2.1.175 tracks/php/exercises/anagram/example.php
trackler-2.2.1.174 tracks/php/exercises/anagram/example.php
trackler-2.2.1.173 tracks/php/exercises/anagram/example.php
trackler-2.2.1.172 tracks/php/exercises/anagram/example.php
trackler-2.2.1.171 tracks/php/exercises/anagram/example.php
trackler-2.2.1.170 tracks/php/exercises/anagram/example.php
trackler-2.2.1.169 tracks/php/exercises/anagram/example.php
trackler-2.2.1.167 tracks/php/exercises/anagram/example.php
trackler-2.2.1.166 tracks/php/exercises/anagram/example.php
trackler-2.2.1.165 tracks/php/exercises/anagram/example.php
trackler-2.2.1.164 tracks/php/exercises/anagram/example.php
trackler-2.2.1.163 tracks/php/exercises/anagram/example.php
trackler-2.2.1.162 tracks/php/exercises/anagram/example.php
trackler-2.2.1.161 tracks/php/exercises/anagram/example.php
trackler-2.2.1.160 tracks/php/exercises/anagram/example.php