我怎么能插入数字

时间:2016-01-15 06:56:28

标签: php arrays

    <?php
      $student_id = array(
        'Parichat' => '5839010042',
        'Tipsuda' => '5839010043',
        'Rungsun' => '5839010045',
        'Matika' => '5839010046',
        'Rawitsara' => '5839010058',
        'Waroonrat' => '5839010059',
        'Wanida' => '5839010061',
        'Naratip' => '5839010062',
        'Lanoy' => '5839010068',
        'Phetsamone' => '5839010069',
        'Khonesamai' => '5839010070',
        'Bukson' => '5839010071',
        'Ratchanigorn' => '5839010072',
        'Sirinart' => '5839010073',
        'Thanupakon' => '5839010081',

      );
      foreach ($student_id as $name => $id) {
      echo "<tr>
              <td></td>
              <td>$name</td>
              <td>$id</td>
            </tr>
      ";
    }
    ?>

2 个答案:

答案 0 :(得分:2)

试试这个

      $i= 1;
      foreach ($student_id as $name => $id) {
      echo "<tr>
              <td>$i</td>
              <td>$name</td>
              <td>$id</td>
            </tr>
      ";
       $i++;
      }

答案 1 :(得分:0)

您的问题是您没有加入<table></table>代码。

<?php
      $student_id = array(
        'Parichat' => '5839010042',
        'Tipsuda' => '5839010043',
        'Rungsun' => '5839010045',
        'Matika' => '5839010046',
        'Rawitsara' => '5839010058',
        'Waroonrat' => '5839010059',
        'Wanida' => '5839010061',
        'Naratip' => '5839010062',
        'Lanoy' => '5839010068',
        'Phetsamone' => '5839010069',
        'Khonesamai' => '5839010070',
        'Bukson' => '5839010071',
        'Ratchanigorn' => '5839010072',
        'Sirinart' => '5839010073',
        'Thanupakon' => '5839010081',

      );
      echo "<table>";
      foreach ($student_id as $name => $id) {
      echo "<tr>
              <td></td>
              <td>$name</td>
              <td>$id</td>
            </tr>
      ";
       }
       echo "</table>";