Home > Article > Backend Development > String increment problem in php
The following code is shown:
$str = 'W'; for( $i=0; $i<6; $i++ ) { echo ++$str . "\r\n"; }
This is because php follows Perl's habits when processing strings, not C's. P For example, er er
$ a = 'z'; $ a ++;will turn
$ ato 'aa' and in c, a = 'z'; a ++ ;
will turna 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.