Skip to content

Instantly share code, notes, and snippets.

@morontt
Created June 24, 2022 13:27
Show Gist options
  • Save morontt/a09e357e333f6f37a19f33c751fb664a to your computer and use it in GitHub Desktop.
Save morontt/a09e357e333f6f37a19f33c751fb664a to your computer and use it in GitHub Desktop.
Excel letter columns to number
<?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