• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 252
  • Last Modified:

Indexing a given character of the alphabet

Hi,

Using php I want to be able to get the character of the alphabet given the index value.

ie. if i pass the value 0 then i get 'A' or if i pass the value 1 i get 'B'

any ideas?

I have seen that rang('A', 'Z') will build the array of characters but I am unsure how I can then get a character from that array given the index number/position.

Thanks,
0
bigMlittleC
Asked:
bigMlittleC
1 Solution
 
EliotBallCommented:
Hi there!
I think this should work. Just call that function, so getLetter(1) will return the string "B". Enjoy!

function getLetter($index)
{
	return substr(rang('A', 'Z'), $index, 1);
}

Open in new window

0
 
mostartCommented:
its called range not rang.. and I don't think you'll need substr:
function getLetter($index)
{
    $alpha = range('A','z');
    return $alpha[$index];
}

Open in new window

0
 
bigMlittleCAuthor Commented:
Thanks guys
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now