增量运算符的混淆[重复]

This question already has an answer here:

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

Above code will output aa00.I'm very confused about this output. Can somebody help me?

</div>

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 this is a string the 99 goes to 00 -> next increment and the Z goes to AA. If you would have done it with Y99 it would have been Z00.

$s = 'W';
for ($n=0; $n<6; $n++) {
    echo ++$s . PHP_EOL;
}

Returns:

X Y Z AA AB AC

Note that decrementing strings won't work in PHP.

$s = 'W';
for ($n=0; $n<6; $n++) {
    echo --$s . PHP_EOL;
}

Returns: W W W W W W