Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

String Increment

String increment is the PHP feature that applies the ++ pre- and post-increment operators on non-numeric strings.

These strings last character’s ASCII code is incremented by one, with possible extension of the string when the letters reach z and Z.

This feature, when based on ++ is deprecated, and shall be removed in version 9. It has been replaced by the str_increment() function, which has the same feature, though not implicit in the engine anymore. It is also extended with It has been replaced by the str_decrement().

A deprecation message is active since PHP 8.3.

<?php

    $s = 'y';
    echo ++$s; // z
    echo ++$s; // aa 
    echo ++$s; // ab
    
    $s = 'Y';
    echo ++$s; // Z
    echo ++$s; // AA
    echo ++$s; // AA

?>

Documentation

See Also