Modify String With Array Syntax

no-email (Damien Seguy), Damien Seguy
Mon, 07 Oct 2024 00:00:00 +0000

PHP strings allows access to individiual 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.