On Fri, Dec 21, 2012 at 7:06 PM, Jim Giner <jim.giner@xxxxxxxxxxxxxxxxxx> 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? That actually depends on what you mean by "unset". If you mean to remove it, str_replace should do, or if you only know it's position, using substr twice to grab the front and back should work. Setting a charcter to null ('') in the middle of the string could be interesting for some applications... Following up with the example I just showed: // now let's 'unset' a character in the middle $s3 = $s; $s3[10] = ''; showstring($s3); yields: String of length 34 is Now we aregone down to the river! s[0] : 'N' 78 s[1] : 'o' 111 s[2] : 'w' 119 s[3] : ' ' 32 s[4] : 'w' 119 s[5] : 'e' 101 s[6] : ' ' 32 s[7] : 'a' 97 s[8] : 'r' 114 s[9] : 'e' 101 s[10] : '' 0 s[11] : 'g' 103 s[12] : 'o' 111 s[13] : 'n' 110 s[14] : 'e' 101 s[15] : ' ' 32 s[16] : 'd' 100 s[17] : 'o' 111 s[18] : 'w' 119 s[19] : 'n' 110 s[20] : ' ' 32 s[21] : 't' 116 s[22] : 'o' 111 s[23] : ' ' 32 s[24] : 't' 116 s[25] : 'h' 104 s[26] : 'e' 101 s[27] : ' ' 32 s[28] : 'r' 114 s[29] : 'i' 105 s[30] : 'v' 118 s[31] : 'e' 101 s[32] : 'r' 114 s[33] : '!' 33 Still 34 byte string length, but looking at s[10] you see the null byte. It didn't really affect printing, but it might affect other things. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php