Link to home
Start Free TrialLog in
Avatar of bigMlittleC
bigMlittleC

asked on

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,
Avatar of EliotBall
EliotBall

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

ASKER CERTIFIED SOLUTION
Avatar of mostart
mostart

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bigMlittleC

ASKER

Thanks guys