Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

for loop from A - Z with PHP [duplicate]

Tags:

php

for-loop

I can make the table perfectly if it's from A-Y but when it if I change it to 'Z', it won't work anymore.

Does anybody know the problem?

<table border="1">
<?php

    for($row=1; $row<=22; $row++){
        echo "<tr>";
        for($column="A"; $column <= "Y"; $column++){
            echo "<td> $row $column </td>";
        }   
        echo "</tr>";
    }
?>
</table>
like image 458
mengmeng Avatar asked Feb 24 '14 17:02

mengmeng


1 Answers

You can try with:

<table border="1">
<?php
   for ($row=1; $row <= 22; $row++){
      echo "<tr>";
      foreach (range('A', 'Z') as $column){
         echo "<td> $row $column </td>";
      }   
      echo "</tr>";
   }
?>
</table>
like image 93
hsz Avatar answered Sep 27 '22 15:09

hsz