Skip to content

Instantly share code, notes, and snippets.

@ravanscafi
Last active July 4, 2016 05:09
Show Gist options
  • Save ravanscafi/a525b6744fd819fb15ac to your computer and use it in GitHub Desktop.
Save ravanscafi/a525b6744fd819fb15ac to your computer and use it in GitHub Desktop.
PHP: Return all unique characters present in an array of strings.
<?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