Created
July 31, 2021 08:25
-
-
Save yokada/76410d22c014ab09f7ce7ff0a8a28e77 to your computer and use it in GitHub Desktop.
convert column name to index 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 | |
/** | |
* convert column name to index number. | |
* | |
* @param string $col 'Z', 'AA', 'ZAA' | |
*/ | |
function col2idx($col = 'AZ') { | |
$idx = 0; | |
$k = count(range('A', 'Z')); | |
$cols = array_reverse(str_split($cols)); | |
foreach ($cols as $i => $c) { | |
$idx += count(range('A', $c)) * pow($k, $i); | |
} | |
return $idx; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment