I have an alphanumeric string like below,
$string_1 = "a4nas60dj71wiena15sdl1131kg12b"
and would like to change it to something like below,
$string_2 = "a4NaS60dJ71wIeNa15Sdl1131Kg12B"
How would I go about doing this? I have tried the below code, but it doesn’t work.
$lenght = strlen($string_1);
for ( $i = 0; $i <= $length - 1; $i += 1) {
if ( $i % 2) {
$string_2[$i]=strtoupper($string_1[$i]);
}
else {
$string_2[$i]=$string_1[$i];
}
}
echo $string_2;
The above code prints out “Array” so something is definitely not working.
By the way, you have a slight error in your capitalized string:
I’ll give you two ways of doing it:
Note: The above makes several assumptions:
The above can be altered if these assumptions are incorrect.