fork(1) download
  1. <?php
  2.  
  3. function unique2($palavra){
  4. $ret = "";
  5.  
  6. for ($i = 0; $i < strlen($palavra); $i++){
  7. if ($i == 0 || $palavra[$i] != $palavra[$i - 1]) $ret .= $palavra[$i];
  8. }
  9. return $ret;
  10. }
  11.  
  12. echo unique2("Banana") . "\n"; // Banana
  13. echo unique2("Arara") . "\n"; // Arara
  14. echo unique2("assassinos") . "\n"; // asasinos
  15. echo unique2("Marreco") . "\n"; // Mareco
  16. echo unique2("Elllizabettth") . "\n"; // Elizabeth
  17. echo unique2("FooBaaar") . "\n"; // FoBar
  18. echo unique2("Woow") . "\n"; // Wow
  19. echo unique2("baazz") . "\n"; // baz
Success #stdin #stdout 0.02s 52472KB
stdin
Standard input is empty
stdout
Banana
Arara
asasinos
Mareco
Elizabeth
FoBar
Wow
baz