Advertisement
rubendivall

just_unique

Feb 21st, 2019
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. /* función PHP para ordenar una lista de palabras y eliminar duplicados separadas por espacios */
  2. function just_unique($string) {
  3.  $array = explode(' ', $string);
  4.  $result = array_unique($array);
  5.  asort($result);
  6.  
  7.  $return = '';
  8.  
  9.  foreach ($result as $value)
  10.  {
  11.    if (strlen($value) > 1) { // solo nos interesarían las palabras de más de 1 letra
  12.     $return.= $value.' ';
  13.    }
  14.  }
  15.  
  16.  $return = trim($return);
  17.  return $return;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement