Indexing a given character of the alphabet

Posted on 2009-04-23
Last Modified: 2012-05-06

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.

Question by:bigMlittleC
    LVL 2

    Expert Comment

    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

    LVL 8

    Accepted Solution

    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


    Author Closing Comment

    Thanks guys

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now