Modify String With Array Syntax¶
PHP strings allows access to individual characters using the array syntax: $string[$index].
It is also possible to modify the string with the same syntax: the index have to be integers.
The positive integers are offsets, starting at zero. Any missing characters between the end of the string and the requested index is set to space ' '. Negative index are also valid, starting from the end of the string.
Here, $a[1] is just after the end of the string, $a[10] is well beyond the end of the string, and $a[-9] is almost back to the beginning of the string.
See Also¶
strings and magic [Try me]