How to get the repeating characters of a string in PHP

1 Answer

0 votes
function get_repeating_chars($s) { 
    $len = strlen($s);
    $tmp = "";
            
    for ($i = 0; $i < $len; $i++) { 
       for ($j = $i + 1; $j < $len; $j++) { 
           if ($s[$i] === $s[$j]) {
               if (strpos($tmp, $s[$i]) === false) {
                   $tmp .= $s[$i];
                   break; 
               }
            } 
        } 
    } 
    return $tmp; 
 } 
  
  
$s = "abcdeffghijgklmbbbbxzx"; 
        
$tmp = get_repeating_chars($s);  
  
echo $tmp;


    
/*
run:

bfgx
         
*/

 



answered Jan 11, 2020 by avibootz
edited Jan 12, 2020 by avibootz

Related questions

1 answer 110 views
1 answer 137 views
1 answer 189 views
2 answers 148 views
1 answer 101 views
...