3v4l.org

run code in 300+ PHP versions simultaneously
<?php $p =<<<EOT That interviews should involve simple code is now common wisdom in programming circles. The story is that a high percentage of programmers, even people with impressive resumes, “just can’t code.” Asked to do the simplest things—problems a good coders could solve as fast they could write—some spend ten or twenty minutes before they get an answer, or fail entirely. (See discussion by Jeff Attwood and Joel Spolsky.) I don’t go as far as others here. I think a lot of “slow coders” are probably excellent employees, making up for it in other areas. Some projects don’t need speed. Some people just need to spend more time programming; everyone was a slow programmer some time. But I know from experience that slow coders don’t work at LibraryThing. They don’t fit the LibraryThing development culture. EOT; $pattern = '[\w\d]+'; $words = array(); preg_match_all('/'.$pattern.'/', $p, $words); $words = $words[0]; $result = array(); foreach ($words as $word) { $len = mb_strlen($word); if (isset($result[$len])) { $result[$len]++; } else { $result[$len] = 1; } } sort($result); foreach ($result as $length => $count) { echo $count.' words with '.$length.' letter.'.PHP_EOL; }
Output for 4.3.10 - 4.3.11, 4.4.0 - 4.4.9, 5.0.2 - 5.0.5, 5.1.0 - 5.1.6, 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.35, 5.6.0 - 5.6.28, 7.0.0 - 7.0.20, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
2 words with 0 letter. 2 words with 1 letter. 4 words with 2 letter. 6 words with 3 letter. 6 words with 4 letter. 7 words with 5 letter. 12 words with 6 letter. 12 words with 7 letter. 15 words with 8 letter. 20 words with 9 letter. 20 words with 10 letter. 34 words with 11 letter.
Output for 4.3.0 - 4.3.9, 5.0.0 - 5.0.1
2 words with 0 letter.PHP_EOL2 words with 1 letter.PHP_EOL4 words with 2 letter.PHP_EOL6 words with 3 letter.PHP_EOL6 words with 4 letter.PHP_EOL7 words with 5 letter.PHP_EOL12 words with 6 letter.PHP_EOL12 words with 7 letter.PHP_EOL15 words with 8 letter.PHP_EOL20 words with 9 letter.PHP_EOL20 words with 10 letter.PHP_EOL34 words with 11 letter.PHP_EOL

preferences:
233.68 ms | 402 KiB | 373 Q