If you want to get the second $str[1] or $str{1}, it is not recommended to use {}. It is better to use []
Test as follows
Copy code The code is as follows:
//Get the last character of the character
$str = 'phpddt.com';
echo $str[strlen($str)- 1]; //m
//Modify the first character
$str = 'phpddt.com';
$str[0] = 'a'; //ahpddt.com
/ / Numbers in square brackets that are out of range will produce blanks.
$str = 'phpddt.com';
$str[100] = 'y'; //phpddt.com y
//If it is a non-integer type, it is converted to an integer
$str = 'phpddt.com';
$str['a'] = 'y'; //phpddt.com y
$str = 'phpddt.com';
$str[-1] = ' y'; //Negative numbers will cause errors: Warning: Illegal string offset: -1
http://www.bkjia.com/PHPjc/744331.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/744331.htmlTechArticleIf you get the second $str[1] or $str{1}, it is not recommended to use {}. Easy to use [] Test the copy code as follows: //Get the last character of the character $str = 'phpddt.com'; echo $str[strlen...