How to find all non repeating characters in a string with PHP

1 Answer

0 votes
function PrintAllNonRepeatedCharacter($str) {
    for ($i = 0; $i <= strlen($str) - 1; $i++) {
        if (substr_count($str, substr($str, $i, 1)) == 1) {
            echo substr($str, $i, 1) . "\n";
        }
    }
}
 
$str = "c c++ csharp java php python";
 
PrintAllNonRepeatedCharacter($str);
 
 
 
 
/*
run:
 
s
r
j
v
y
t
o
n
 
*/

 



answered Sep 4, 2022 by avibootz

Related questions

1 answer 117 views
1 answer 138 views
1 answer 124 views
1 answer 140 views
1 answer 113 views
...