SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2009
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up plz guide me once more

    Hi php experts!
    plz guide me once more..... How to create an array of the letters of the English alphabet?

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $letters = array('a''b''c''d''e''f''g''h''i''j''k''l''m''n''o''p''q''r''s''t''u''v''w''x''y''z'); 
    PHP Code:
    $letters range('a''z'); 
    PHP Code:
    $letters = array();
    for (
    $i 97$i 123$i++)
      
    $letters[] = chr($i); 

  3. #3
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $all 
    'the quick brown fox jumps over the lazy dog';
    $alphabet = array();

    for(
    $i=0$i<strlen($all); $i++) {
        
    $char $all[$i];
        if(
    $char != ' ' AND !in_array($char$alphabet)) $alphabet[] = $char;
    }

    var_dump($alphabet);

  4. #4
    John 8:24 JREAM's Avatar
    Join Date
    Sep 2007
    Location
    Florida
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $alphabet = array();
    for (
    $i=65$i<=90$i++) {

        
    $alphabet[] = chr($i); 
        
    $alphabet[] = strtolower(chr($i));
        } 

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2009
    Location
    Brisbane, Australia
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    class Alpha
    {
        protected 
    $_charMap = array(
            
    0x410x420x430x440x450x46,
            
    0x470x480x490x4A0x4B0x4C,
            
    0x4D0x4E0x4F0x500x510x52,
            
    0x530x540x550x560x570x58,
            
    0x590x5A,             0x610x62,
            
    0x630x640x650x660x670x68,
            
    0x690x6A0x6B0x6C0x6D0x6E,
            
    0x6F0x700x710x720x730x74,
            
    0x750x760x770x780x790x7A,
        );
        
        public function 
    getUpper()
        {
            return 
    array_map('chr'array_slice($this->_charMap026));
        }
        
        public function 
    getLower()
        {
            return 
    array_map('chr'array_slice($this->_charMap26));
        }


  6. #6
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    So, did we guide you successfully?

  7. #7
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think more guiding is needed dan.

    PHP Code:
    class EnglishLetterIterator implements IteratorCountable {
        private 
    $position;
        public function 
    __construct() { $this->rewind(); }
        function 
    rewind() { $this->position 65; }
        function 
    current() { return chr($this->position); }
        function 
    key() { return $this->position 65; }
        function 
    next() { $this->position++; }
        function 
    valid() { return $this->position <= 90; }
        function 
    count() { return 26; }
    }

    foreach (new 
    EnglishLetterIterator() as $char) {
        echo 
    $char;



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •