Last active
August 29, 2015 14:23
-
-
Save tkshnwesper/89c1b6ff72de71f55a95 to your computer and use it in GitHub Desktop.
Incrementer
This file contains 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
function getIncrement($str) { | |
$len = strlen($str); | |
if($str === '') { | |
return '0'; | |
} | |
for($i = $len - 1; $i >= 0; $i--) { | |
if($str[$i] === '9') { | |
$str[$i] = 'A'; | |
break; | |
} | |
if($str[$i] === 'Z') { | |
$str[$i] = 'a'; | |
break; | |
} | |
if($str[$i] === 'z') { | |
$str[$i] = '0'; | |
if($i === 0) { | |
$str = '0' . $str; | |
break; | |
} | |
} | |
else { | |
$str[$i] = chr(ord($str[$i]) + 1); | |
break; | |
} | |
} | |
return $str; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment