Last active
July 4, 2016 05:09
-
-
Save ravanscafi/a525b6744fd819fb15ac to your computer and use it in GitHub Desktop.
PHP: Return all unique characters present in an array of strings.
This file contains 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
<?php | |
/** | |
* Return all unique characters present in an array of strings. | |
* It ignores spaces due to join(). | |
* e.g.: | |
* ['abc', 'g', 'def', 'abcd']; | |
* > 'abcdefg' | |
* | |
* @param array $array | |
* | |
* @return string | |
*/ | |
function charList(array $array) | |
{ | |
$letters = array_unique(preg_split('//u', join('', $array))); | |
sort($letters); | |
return join('', $letters); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment