Skip to content

Instantly share code, notes, and snippets.

@MrPunyapal
Created November 28, 2023 15:48
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MrPunyapal/94fc45f4912b9267c9e3587a455742ca to your computer and use it in GitHub Desktop.
Save MrPunyapal/94fc45f4912b9267c9e3587a455742ca to your computer and use it in GitHub Desktop.
Exploring PHP 8.3: Alphanumeric String Magic ✨
<?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