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