Created
November 28, 2023 15:48
-
-
Save MrPunyapal/94fc45f4912b9267c9e3587a455742ca to your computer and use it in GitHub Desktop.
Exploring PHP 8.3: Alphanumeric String Magic ✨
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// PHP 8.3 introduces exciting new functions for | |
// incrementing and decrementing alphanumeric strings! | |
// Let's dive into some examples to see how they work. | |
// str_increment — Increment an alphanumeric string | |
echo str_increment("a") . PHP_EOL; // b | |
echo str_increment("z") . PHP_EOL; // aa | |
echo str_increment("az") . PHP_EOL; // ba | |
echo str_increment("zz") . PHP_EOL; // aaa | |
echo str_increment("zzz") . PHP_EOL; // aaaa | |
echo str_increment("1") . PHP_EOL; // 2 | |
echo str_increment("a1") . PHP_EOL; // a2 | |
echo str_increment("a9") . PHP_EOL; // b0 | |
echo str_increment("aZ") . PHP_EOL; // bA | |
echo str_increment("aZz") . PHP_EOL; // bAa | |
// str_decrement — Decrement an alphanumeric string | |
echo str_decrement("b") . PHP_EOL; // a | |
echo str_decrement("aa") . PHP_EOL; // z | |
echo str_decrement("ba") . PHP_EOL; // az | |
echo str_decrement("aaa") . PHP_EOL; // zz | |
echo str_decrement("aaaa") . PHP_EOL; // zzz | |
echo str_decrement("2") . PHP_EOL; // 1 | |
echo str_decrement("a2") . PHP_EOL; // a1 | |
echo str_decrement("b0") . PHP_EOL; // a9 | |
echo str_decrement("bA") . PHP_EOL; // aZ | |
echo str_decrement("bAa") . PHP_EOL; // aZz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment