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

后端 未结 14 782
情话喂你
情话喂你 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: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
    

提交回复
热议问题