Write a PHP program to find the first non-repeated character in a given string.
Sample Example:
Input: GreenOutput: GInput: abcdeaOutput: b
<?php function find_non_repeat($word) { $chr = null; for ($i = 0; $i <= strlen($word); $i++) { if (substr_count($word, substr($word, $i, 1)) == 1) { return substr($word, $i, 1); } } } echo find_non_repeat("Green")."\n"; echo find_non_repeat("abcdea")."\n"; ?>
Sample Output:
G b
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer