3 ms·
Pfft <?php function top10($s) { $a = array_count_values(preg_split('/\b\s+/', $s)); arsort($a); return array_slice($a, 0, 10); }
by Myrth 13y ago
Pfft <?php function top10($s) { $a = array_count_values(preg_split('/\b\s+/', $s)); arsort($a); return array_slice($a, 0, 10); }
- tracker1 13y agoYou managed to create an example of why I don't care for PHP... array_count_values(...) arsort(...) array_slice(...) Thinking.. two of these things belong together, two of these things are kind of the same.. but one of these things is doing his own thing... Seriously built in method naming and argument ordering don't follow any consistent convention in PHP, that's always been the most irksome thing to me...
- Myrth 13y agoWelp oops: <?php function top10($s) { $a = array_count_values(preg_split('/\b\s+/', $s)); rsort($a); return array_slice(array_keys($a), 0, 10); }