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.

Revisions

  1. yokada created this gist Jul 31, 2021.
    16 changes: 16 additions & 0 deletions col2idx.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    <?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;
    }