Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to list Alphabetical(A-Z) using PHP

Tags:

php

I need to print/list alphabetical(A-Z) chararcters to manage Excel cells. Is there any PHP function to list alphabetic?

I need result as

A1 B1 C1 D1 ... ... 

OR

A B C ... ... 

Is this possible?

like image 978
Prabhu M Avatar asked May 18 '10 12:05

Prabhu M


People also ask

How to display alphabet in PHP?

All alphabetic characters in an array can be achieved by using chr(), range() with for and foreach loop in PHP. To display the array elements as output we can use echo, print_r() and var_dump() function.

How to get numeric position of alphabets in PHP?

php $upperArr = range('A', 'Z') ; $LowerArr = range('a', 'z') ; $myLetter = 't'; if(ctype_upper($myLetter)){ echo (array_search($myLetter, $upperArr) + 1); }else{ echo (array_search($myLetter, $LowerArr) + 1); } ?>


1 Answers

You can either do:

foreach (range('A', 'Z') as $char) {     echo $char . "\n"; } 

Or:

for ($char = 'A'; $char <= 'Z'; $char++) {     echo $char . "\n"; } 
like image 190
Alix Axel Avatar answered Sep 21 '22 20:09

Alix Axel