drtpbx3606 2016-05-29 02:24
浏览 36

如何使用foreachloop将数组数据放在表中[重复]

This question already has an answer here:

I keep getting the error: Parse error: syntax error, unexpected 'sNameâ€' (T_STRING), expecting ']'on line 5 I need some help solving this problem. Could anyone tell me what's wrong with my code?

<!DOCTYPE html>
<?php
$data = array [
                ["sName” => “Gervase”, "sNumber" => "s1234567", "mark” => 95, “comments” => “Well done!”],
                ["sName” => “Matt”, "sNumber" => "s1234567", "mark” => 95, “comments” => “Well done!”],
                ["sName” => “Kid”, "sNumber" => "s1234567", "mark” => 95, “comments” => “Well done!”],
                ["sName” => “Nathan”, "sNumber" => "s1234567", "mark” => 85, “comments” => “Well done!”]
  ]
?>
<html>
<head>
    <link type='text/css' rel='stylesheet' href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"/>
</head>
    <body>
        <div>
            <div class="jumbotron">
                 <div>
                     <div class="container">
                         <h1>Data</h1>
                 </div>
                 <div>
                 <div class="container">
                   <table>
                        <table class="table">
                             <thead>  
                           <?php

                            foreach ($data as $data)
                            {
                                echo"<tr>";
                                echo"<td>".$data["sName"]."</td>";
                                echo"<td>".$data["sNumber"]."</td>";
                                echo"</tr>";
                            }
                            ?>
                                 <tr>
                                   <th>Student number</th>
                                   <th>Student name</th>
                                   <th>Mark</th>
                                   <th>Comments</th>
                                 </tr>
                                 <tr>
                                   <td>Something</td>
                                 </tr>
                             </thead>
                   </table>
                 </div<
       </div>
    </body>

</div>
  • 写回答

3条回答 默认 最新

  • doucuoyan0426 2016-05-29 02:52
    关注

    Given the current code, it may be related to the missing semi-colon after the closing bracket of the $data array.

    Beyond that, it looks like your code is mixing different characters that represent quotation marks. You can see this based on the formatting colors SO applied in your question block. Try re-typing the array directly in your editor (rather than copy-and-pasting or something) so that all the characters match up, and see if that helps.

    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)