Skip to content

Instantly share code, notes, and snippets.

@xuannghia
Last active August 25, 2018 07:23
Show Gist options
  • Save xuannghia/cdf7c217c9e4fc5cfe7affc323148a4c to your computer and use it in GitHub Desktop.
Save xuannghia/cdf7c217c9e4fc5cfe7affc323148a4c to your computer and use it in GitHub Desktop.
Chuyển index sang dạng chữ alphabet. 0 => A; 1 => B;...25 => Z; 26 => AA...
<?php
// Get alphabet from index number
// 0 => A; 1 => B
// 25 => Z; 26 => AA
function get_alphabet_from_index($num)
{
$numeric = $num % 26;
$letter = chr(65 + $numeric);
$num2 = intval($num / 26);
if ($num2 > 0) {
return get_alphabet_from_index($num2 - 1) . $letter;
} else {
return $letter;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment