3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('ALNUM_MAP', str_split('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789')); define('DIGIT_MAP', array_flip(ALNUM_MAP)); function numToAlnum($num) { return strtr($num, ALNUM_MAP); } function alnumToNum($alphaNum) { return strtr($alphaNum, DIGIT_MAP); } $ids = ['4440', '464426', '43304441302845', '262018191701180', '273381111186152545352']; foreach ($ids as $id) { $idLength = strlen($id); $alphaNum = numToAlnum($id); $alNumLength = strlen($alphaNum); $backToId = alnumToNum($alphaNum); var_export(['original' => $id, 'encoded' => $alphaNum, 'decoded' => $backToId, 'reduction' => $idLength - $alNumLength]); echo "\n---\n"; }
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.26, 7.4.0 - 7.4.13, 8.0.0 - 8.0.3
array ( 'original' => '4440', 'encoded' => 'SO', 'decoded' => '4440', 'reduction' => 2, ) --- array ( 'original' => '464426', 'encoded' => 'USA', 'decoded' => '464426', 'reduction' => 3, ) --- array ( 'original' => '43304441302845', 'encoded' => 'RESPECT', 'decoded' => '43304441302845', 'reduction' => 7, ) --- array ( 'original' => '262018191701180', 'encoded' => 'Australia', 'decoded' => '262018191701180', 'reduction' => 6, ) --- array ( 'original' => '273381111186152545352', 'encoded' => 'BHills90210', 'decoded' => '273381111186152545352', 'reduction' => 10, ) ---