1. 程式人生 > >PHP三維陣列的定義與遍歷

PHP三維陣列的定義與遍歷

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>三層forecach</title>
  </head>
  <body>
    <?php
        $wage = array(
          "大一" => array(
            array(1, '張', '班長', '19'),
            array(2, '李','學委','18'),
            array
(3, '王','學生','19'), ), "大二" => array( array(1, '趙', '班長', '19'), array(2, '周','學委','18'), array(3, '郭','學生','19') ), "大三" => array( array(1, '孫' , '班長' , '19'), array(2, '魯' , '學委' , '18'), array
(3, '林' , '學生' , '19') ) ); foreach ($wage as $table) { # code... echo '<table border="1"; width="600";align="center">'; echo '<caption><h1>我的個人資訊</h1></caption>'; echo '<tr bgcolor="#DDDDDD">'; echo
'<td>編號</td><td>姓名</td><td>職位</td><td>年齡</td>'; echo '</tr>'; foreach ($table as $row) { # code... echo '<tr>'; foreach ($row as $col) { # code... echo '<td>'.$col.'</td>'; } echo '</tr>'; } } ?>
</body> </html>