Re: Strange string stuff -- maybe everything is ending...

From: Date: Sat, 22 Dec 2012 19:34:00 +0000
Subject: Re: Strange string stuff -- maybe everything is ending...
Groups: php.general 
Request: Send a blank email to php-general+get-319944@lists.php.net to get a copy of this message
On 22 Dec 2012 at 16:50, Tedd Sperling <tedd@sperling.com> wrote: > On Dec 21, 2012, at 8:06 PM, Jim Giner <jim.giner@albanyhandball.com> wrote: >>> That actually makes sense tho. Afterall, a string is truly only one memory >>> allocation whereas array elements are basically multiple vars having the >>> same name. So - how can you unset one char in a string? > > It depends upon the language -- while it is true that the start of a string is > located at a memory address, the chars of the string are identical to the > chars in an array. As such, you can view a string as an array. Each index is > representative of a char (one byte) in the string. That is explicitly documented here: <http://php.net/manual/en/language.types.string.php> String access and modification by character Characters within strings may be accessed and modified by specifying the zero-based offset of the desired character after the string using square array brackets, as in $str[42]. Think of a string as an array of characters for this purpose. The functions substr() and substr_replace() can be used when you want to extract or replace more than 1 character. -- Cheers -- Tim

« previous php.general (#319944) next »