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

前端 未结 11 2068
迷失自我
迷失自我 2020-12-13 13:33

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
..         


        
相关标签:
11条回答
  • 2020-12-13 13:57

    I think you should use the range function:

    $a=range("A","Z");
    foreach($a as $char)
        echo $char."\n";
    
    0 讨论(0)
  • 2020-12-13 13:58

    You can either do:

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

    Or:

    for ($char = 'A'; $char <= 'Z'; $char++) {
        echo $char . "\n";
    }
    
    0 讨论(0)
  • 2020-12-13 13:59

    If you're looking for a comprehensive set of Excel functionality, then take a look at PHPExcel which provides a lot of methods for manipulating cell addresses and ranges, as well as reading/writing for Excel and various other spreadsheet file formats

    0 讨论(0)
  • 2020-12-13 14:07

    This code for display A,B,...,ZY,ZZ.

    function print_char($end_no=90, $start_no=65, $prefix_no=0)
    { $vasant='';
        if($prefix_no==0)
        {
            for($set=$start_no; $set<=$end_no; $set++)
            {
                $vasant.=(chr($prefix_no).chr($set)).', ';
            }
        }
        else
        {
            for($set=$start_no; $set<=90; $set++)
            {
                $vasant.=(chr($set)).', ';
            }
            for($pre_loop=65; $pre_loop<=$prefix_no; $pre_loop++)
            {
                for($set=$start_no; $set<=90; $set++)
                {
                    if($set>=$end_no && $pre_loop==$prefix_no)
                    {
                        $vasant.=(chr($pre_loop).chr($set)).'. ';
                        break;
                    }
                    else
                    {
                        $vasant.=(chr($pre_loop).chr($set)).', ';
                    }
                }
            }
        }
        return $vasant;
    }
    
    
    $show=print_char(90,65,90);
    echo $show;
    
    0 讨论(0)
  • 2020-12-13 14:09

    You can do it in this way as well: ASCII range used here.

    for($i = 65 ; $i<=90; $i++)
    {
      echo chr($i);
    }
    
    0 讨论(0)
提交回复
热议问题