php - A confision of increment operator -


this question has answer here:

$a = 'z99'; var_dump(++$a); 

above code output aa00.i'm confused output. can me?

that's because php follows perl's convention.

you can find more information on http://php.net/manual/en/language.operators.increment.php

so because string 99 goes 00 -> next increment , z goes aa. if have done y99 have been z00.

$s = 'w'; ($n=0; $n<6; $n++) {     echo ++$s . php_eol; } 

returns:

x y z aa ab ac

note decrementing strings won't work in php.

$s = 'w'; ($n=0; $n<6; $n++) {     echo --$s . php_eol; } 

returns: w w w w w w


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -