Skip to content

Instantly share code, notes, and snippets.

@yokada
Created July 31, 2021 08:25
Show Gist options
  • Save yokada/76410d22c014ab09f7ce7ff0a8a28e77 to your computer and use it in GitHub Desktop.
Save yokada/76410d22c014ab09f7ce7ff0a8a28e77 to your computer and use it in GitHub Desktop.
convert column name to index number
<?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