function remove_all_occurrences($s, $ch) {
$n = strlen($s);
$total = 0;
for ($i = $j = 0; $i < $n; $i++) {
if ($s[$i] != $ch) {
$s[$j++] = $s[$i];
}
else {
$total++;
}
}
while($total--) {
$s[$j++] = " ";
}
return $s;
}
$s = "php programming version 7.3.1";
$s = remove_all_occurrences($s, 'p');
echo $s;
/*
run:
h rogramming version 7.3.1
*/