Home  >  Article  >  Backend Development  >  String increment problem in php

String increment problem in php

WBOY
WBOYOriginal
2016-07-30 13:30:311383browse

The following code is shown:

$str = 'W';
for( $i=0; $i<6; $i++ )
{
	echo ++$str . "\r\n";
}

The following results will appear:

This is because php follows Perl's habits when processing strings, not C's. P For example, er er

$ a = 'z'; $ a ++;

will turn

$ a

to 'aa' and in c, a = 'z'; a ++ ;

will turn

a into '[' (the ASCII value of 'Z' is 90, and the ASCII value of '[' is 91).


Character variables can only be incremented, not decremented, and only support pure letters (a-z and A-Z). Incrementing/decrementing other character variables is invalid and the original string will not change.


Copyright Statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.

The above introduces the problem of string increment in PHP, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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
Previous article:php file upload functionNext article:php file upload function