3v4l.org

run code in 300+ PHP versions simultaneously
<?php function getWordsWithOnlySpecifedLetters(array $dictionary, $letters) { $strSplit = preg_split('//u', $letters, null, PREG_SPLIT_NO_EMPTY); $strSplitLower = array_map('mb_strtolower', $strSplit); sort($strSplit); $result = []; foreach ($dictionary as $word) { if(mb_strlen($word) <= mb_strlen($letters)) { $wordSplit = preg_split('//u', $word, null, PREG_SPLIT_NO_EMPTY); sort($wordSplit); if (array_map('mb_strtolower', $wordSplit) === $strSplitLower) { $result[] = $word; } } } return $result; } $dictionary = ['apple', 'sample', 'api', 'pia', 'тоҷик']; echo '<pre>' . print_r(getWordsWithOnlySpecifedLetters($dictionary, "aip"), true) . '</pre>';
Output for 8.1rc1 - rc3
Deprecated: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated in /in/tBnY6 on line 5 Deprecated: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated in /in/tBnY6 on line 11 Deprecated: preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated in /in/tBnY6 on line 11 <pre>Array ( [0] => api [1] => pia ) </pre>
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.33, 7.3.16 - 7.3.33, 7.4.0 - 7.4.26, 8.0.0 - 8.0.13
<pre>Array ( [0] => api [1] => pia ) </pre>

preferences:
33.96 ms | 461 KiB | 5 Q