chinmay.sahoo
New member
Individual characters in a string can be accessed using the $str{offset} notation. You can use it to both read and write string offsets. When reading characters, this notation should be used only to access valid indices. When modifying characters, you may access offsets that don’t yet exist. PHP automatically sets that offset to the said character, and if this results in a gap between the ending of the original string and the offset of the new character, the gap filled with space characters (' ').
This example creates and prints the string "Andi" (in an awkward way):
This example creates and prints the string "Andi" (in an awkward way):
$str = "A";
$str{2} = "d";
$str{1} = "n";
$str = $str . "i";
print $str;