I have two strings like this
$text = 'Abcdef';
$text[7] = 'Ghijk';
When I take the length of $text by
echo strlen($text);
The answer is 8. Can Any body describe how is it?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Take a simpler example to see what happens:
When PHP sees that we are accessing index
2of the string whose length is 1 (with only valid index being 0), it extends the string by adding two spaces, so it makes the string'a '.Next the index operator
[]deals with characters in the string. So your second statement replaces the 3rd character with ab, giving youa b