Way to get all alphabetic chars in an array in PHP?

后端 未结 14 673
情话喂你
情话喂你 2020-12-22 20:44

Is there a way to get all alphabetic chars (A-Z) in an array in PHP so I can loop through them and display them?

相关标签:
14条回答
  • 2020-12-22 21:30

    All good answers, in case someone is looking for an array of lower and upper case alphabets, here it is:

    $alpha = 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','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');
    
    0 讨论(0)
  • 2020-12-22 21:32

    If you need an array that has alphabetical keys as well as elements (for an alphabetical dropdown list, for example), you could do this:

    $alphas = array_combine(range('A','Z'),range('A','Z'))
    

    Yields:

    array (size=26)
      'A' => string 'A' (length=1)
      'B' => string 'B' (length=1)
      'C' => string 'C' (length=1)
      'D' => string 'D' (length=1)
      ...etc
    
    0 讨论(0)
提交回复
热议问题