Home > Backend Development > PHP Tutorial > PHP accesses and modifies string characters like an array_PHP Tutorial

PHP accesses and modifies string characters like an array_PHP Tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:35:22
Original
813 people have browsed it

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

www.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...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template