วันศุกร์ที่ 11 กันยายน พ.ศ. 2558

ว่างๆก็ลองเขียนโค้ด php ดูดีกว่า

อ่านๆ pantip แล้วไปเจอกระทู้ถามว่า "โค้ด Factorial ภาษา php ใครสามารถทำได้บ้างง" ไหนๆก็ลองเขียนจนออกมาแล้วเก็บไว้เตือนความทรงจำว่าครั้งนึงก็เคยเขียน php


  1. <php?
  2. echo '<table style="width:100%" >
  3.              <tr align="center">
  4.                 <td>round</td>
  5.                 <td>number</td>
  6.                  <td>factorial</td>
  7.                  <td>parameter</td>
  8.                  <td align="left">display</td>
  9.               </tr>';

  10. $round;
  11. $number=6;
  12. $param = $number-1;
  13. $factorStr = '6';
  14. for($round = 1;$round<$number;$round++)
  15. {

  16.   $factorStr=$factorStr.'*'.$param;
  17.   echo '<tr align="center">
  18.                     <td>'.$round.'</td>
  19.                     <td>'.($number-$round+1).'</td>                
  20.                     <td>'.($number-$round+1).'-1</td>
  21.                     <td>'.$param.'</td>                  
  22.                     <td  align="left">Factorial is '.$factorStr.'</td>                                                              
  23.               </tr>';
  24.   $param--;
  25. }
  26. ?>