用while和for循環嵌套輸出表格

 
   <html>
   <head>
      <title>使用while循環嵌套輸出表格</title>
   </head>
   <body>
      <?php 
        echo"<table align='center' border=1 width=600>";
          echo"<caption>";
          echo"<h1>使用while循環嵌套輸出表格</h1>";
          echo"</caption>";
         $out=0;
         while($out<10){
         	if($out%2==0){
         		$bgcolor="#ffffff";
         	}else{
         		$bgcolor="#dddddd";
         	}
         	echo"<tr align='center' bgcolor=".$bgcolor.">";
         	$in=0;
         	while($in<10){
         		echo"<td>".($out*10+$in)."</td>";
         		$in++;
         	}
         	echo"</tr>";
         	$out++;
         }
         echo"</table>";
      ?>
      <?php 
      echo"<table align='center' border=1 width=600>";
          echo"<caption>";
          echo"<h1>使用for循環嵌套輸出表格</h1>";
          echo"</caption>";
         for($ou=0;$ou<10;$ou++){
         	if($ou%10==0)
         	   $bgc="#ffffff";
         	 else
         	    $bgc="#dddddd";
         	 echo"<tr align='center' bgcolor=".$bgc.">"; 
         	 for($it=0;$it<10;$it++){
         	 	echo"<td>".(10*$ou+$it)."<?td>";
         	 }
         	 echo"</tr>";
         }
         echo"</table>";
      ?>
   </body>
   </html>

發佈了36 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章