function get_last_character_repeated($s) {
$len = strlen($s);
$ch_idx = -1;
for ($i = 0; $i < $len; $i++) {
for ($j = $i + 1; $j < $len; $j++) {
if ($s[$i] == $s[$j]) {
$ch_idx = $i;
break;
}
}
}
return $ch_idx;
}
$s = "abcdxypcbadom";
$i = get_last_character_repeated($s);
if ($i == -1) {
echo "Not found";
}
else {
echo $s[$i];
}
/*
run:
d
*/