Created
June 24, 2022 13:27
-
-
Save morontt/a09e357e333f6f37a19f33c751fb664a to your computer and use it in GitHub Desktop.
Excel letter columns to number
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
<?php | |
function number($str) { | |
$arr = str_split($str); | |
$sum = 0; | |
for ($i = count($arr) - 1; $i >= 0; $i--) { | |
$idx = ord(strtoupper($arr[$i])) - 64; | |
$sum += $idx * (26 ** (count($arr) - $i - 1)); | |
} | |
echo strtoupper($str) . " : " . $sum . "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment