Sha256: 8364f89a807e2634a643bdc0dbb7a28a0f3d879af175cfc2763d92a1bc59b69d

Contents?: true

Size: 407 Bytes

Versions: 396

Compression:

Stored size: 407 Bytes

Contents

<?php

function wordCount($phrase)
{
    $count = [];

    $phrase = preg_replace(['/[^a-zA-Z0-9]+/', '/\s\s/'], ' ', mb_strtolower($phrase));

    foreach (explode(' ', $phrase) as $word) {
        if (!array_key_exists($word, $count) && !empty($word)) {
            $count[$word] = 1;
        } elseif (array_key_exists($word, $count)) {
            $count[$word]++;
        }
    }

    return $count;
}

Version data entries

396 entries across 396 versions & 1 rubygems

Version Path
trackler-2.2.1.139 tracks/php/exercises/word-count/example.php
trackler-2.2.1.138 tracks/php/exercises/word-count/example.php
trackler-2.2.1.137 tracks/php/exercises/word-count/example.php
trackler-2.2.1.136 tracks/php/exercises/word-count/example.php
trackler-2.2.1.135 tracks/php/exercises/word-count/example.php
trackler-2.2.1.134 tracks/php/exercises/word-count/example.php
trackler-2.2.1.133 tracks/php/exercises/word-count/example.php
trackler-2.2.1.132 tracks/php/exercises/word-count/example.php
trackler-2.2.1.131 tracks/php/exercises/word-count/example.php
trackler-2.2.1.130 tracks/php/exercises/word-count/example.php
trackler-2.2.1.129 tracks/php/exercises/word-count/example.php
trackler-2.2.1.128 tracks/php/exercises/word-count/example.php
trackler-2.2.1.127 tracks/php/exercises/word-count/example.php
trackler-2.2.1.126 tracks/php/exercises/word-count/example.php
trackler-2.2.1.125 tracks/php/exercises/word-count/example.php
trackler-2.2.1.124 tracks/php/exercises/word-count/example.php
trackler-2.2.1.123 tracks/php/exercises/word-count/example.php
trackler-2.2.1.122 tracks/php/exercises/word-count/example.php
trackler-2.2.1.121 tracks/php/exercises/word-count/example.php
trackler-2.2.1.120 tracks/php/exercises/word-count/example.php