Need to replace a char from another string.
$s1='123456789';
$s2='abcdefghi';
$p=4; // position of char in $s1 to use for replacing (0 is first char)
$s2 = ???? ; // code
In the end $s2 must be 'abcd5fghi'
What would be fastest method?
Need to replace a char from another string.
$s1='123456789';
$s2='abcdefghi';
$p=4; // position of char in $s1 to use for replacing (0 is first char)
$s2 = ???? ; // code
In the end $s2 must be 'abcd5fghi'
What would be fastest method?
If you only have single-byte characters:
$s2[$p] = $s1[$p];
Otherwise, in case of multi-byte characters, you will probably need to use mb_substr
:
$s2 = mb_substr($s2, 0, $p).mb_substr($s1, $p, 1).mb_substr($s2, $p+1);