String increment problem in php

WBOY
Release: 2016-07-30 13:30:31
Original
1387 people have browsed it

The following code is shown:

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

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.

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template