$fr = "hammad";
$frhammad = "nuthing";
echo $fr{$fr};
Output:
h
Whereas the expected output was
"Nuthing"
What Should be the format to echo “Nuthing”?
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.
Because $x{$n} is standard syntax that treats the string $x as an array of characters, where $n is the numeric index position of a character in that aray. In your case the index position is identified by $fr, which is a non-numeric string, so PHP’s loose typing is converting it to an integer 0, and so echoing the character at position 0… the first character of the string
EDIT
obligatory quote from the manual:
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.
Note: Strings may also be accessed using braces, as in $str{42}, for the same purpose.
EDIT #2
To answer your latest question from the comments:
or