Created
October 1, 2020 14:35
-
-
Save Amegatron/7d5045352bc6e2513256828d7c98f2f7 to your computer and use it in GitHub Desktop.
Test function for Dostavista
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function popularWords($text, $amount = 5) | |
{ | |
$top = []; | |
$words = preg_split('~[^[:alnum:]]+~is', strtolower($text), -1, PREG_SPLIT_NO_EMPTY); | |
foreach ($words as $word) { | |
if (!isset($top[$word])) { | |
$top[$word] = 0; | |
} | |
$top[$word]++; | |
} | |
arsort($top); | |
return array_slice($top, 0, $amount, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment